수신 할 수없는 Azure 서비스 대기열에 메시지가 있습니다. 그리고 나는 문제가 무엇인지에 관해 어떤 지표도 얻지 못하고있다. 메시지 크기와 관련이 있다고 생각합니다. 아래 코드에서 OpenFileDialog를 사용하고있는 것을 볼 수 있습니다. jpeg 이미지를 선택 중이며 대기열로 전송됩니다. 이제 약 50KB 미만의 작은 이미지를 보내면 수신 프로세스에 의해 잘 표시되지만 100KB를 넘는 이미지는 대기열에 머물러 있습니다. MSDN에서는 메시지 크기 제한이 256KB이므로 여기에서 무슨 일이 일어나고 있는지 잘 모르겠습니다.메시지가 대기열에있을 때 Azure 서비스 버스 대기열 - QueueClient.Receive()가 null을 반환합니다.
두 클래스가 있습니다. 하나는 SendToQueue이고 다른 하나는 RecvFromQueue입니다. 여기에 코드가 있습니다.
using System;
using System.IO;
using System.Windows.Forms;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;
using Microsoft.WindowsAzure;
namespace ServiceBusQueueApp
{
public class SendToQueue
{
private const string c_testqueue = "TestQueue";
[STAThreadAttribute]
static void Main(string[] args)
{
// Configure Queue Settings
QueueDescription qd = new QueueDescription(c_testqueue)
{
MaxSizeInMegabytes = 5120,
DefaultMessageTimeToLive = new TimeSpan(1, 1, 0)
};
// Create a new Queue with custom settings
string connectionString =
CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
var namespaceManager =
NamespaceManager.CreateFromConnectionString(connectionString);
if (!namespaceManager.QueueExists(c_testqueue))
{
namespaceManager.CreateQueue(qd);
}
namespaceManager.DeleteQueue(qd.Path);
namespaceManager.CreateQueue(qd);
QueueClient client = QueueClient.CreateFromConnectionString(connectionString, c_testqueue);
double maxSize = Math.Pow(2, 18);
OpenFileDialog openFile = new OpenFileDialog();
while (true)
{
if (openFile.ShowDialog() == DialogResult.Cancel)
{
break;
}
var messageBodyStream = new FileStream(openFile.FileName, System.IO.FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
if (messageBodyStream.Length > maxSize)
{
MessageBox.Show("File is larger than 256KB.");
continue;
}
BrokeredMessage msg =
new BrokeredMessage(messageBodyStream);
msg.Properties["MyProperty"] = "Test Value";
try
{
//send msg to the queue
client.Send(msg);
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
throw;
}
}
}
}
}
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows.Forms;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;
using Microsoft.WindowsAzure;
namespace ServiceBusQueueApp
{
class RecvFromQueue
{
private const string c_testqueue = "TestQueue";
static void Main(string[] args)
{
// Create a new Queue with custom settings
string connectionString =
CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
var namespaceManager =
NamespaceManager.CreateFromConnectionString(connectionString);
if (!namespaceManager.QueueExists(c_testqueue))
{
MessageBox.Show("Queue does not exist.");
throw new Exception("Queue does not exist.");
}
QueueClient client = QueueClient.CreateFromConnectionString(connectionString, c_testqueue);
while (true)
{
BrokeredMessage message = client.Receive();
if (message == null)
{
continue;
}
try
{
Stream fstream = message.GetBody<Stream>();
byte[] buffer = new byte[fstream.Length];
fstream.Read(buffer, 0, (int)fstream.Length);
File.WriteAllBytes(@"C:\users\roberthar\pictures\testpic.png", buffer);
fstream.Close();
Process paint = new Process();
paint.StartInfo.FileName = @"C:\Windows\System32\mspaint.exe";
paint.StartInfo.Arguments = @"C:\users\roberthar\pictures\testpic.png";
paint.Start();
Thread.Sleep(3000);
paint.Close();
// Remove message from queue
message.Complete();
}
catch (Exception exception)
{
// Indicate a problem, unlock message in queue
message.Abandon();
}
}
}
}
}
죄송합니다. 매우 늦다는 것을 알고 있습니다 만, 수신 코드에 어떤 종류의 로깅을 추가하는 것이 좋습니다. 이 코드는 큐 관련 또는 파일 관련 예외를 포착하고 로그없이 메시지를 포기합니다. 예외 세부 사항을 기록하지 않으면 실제 오류가 표시되지 않으므로 해결할 수 있습니다. – Joon