MSMQ 专用队列 - 未接收
MSMQ 新手...我的本地队列从未收到我的测试消息。我已验证消息队列和消息队列触发器正在我的“服务”对话框 (Vista Ultimate) 中运行。想法?
class ConsoleApplication
{
private const string Path = @".\private$\SomeQueue";
static void Main(string[] args)
{
var queue = !MessageQueue.Exists(Path)
? MessageQueue.Create(Path)
: new MessageQueue(Path) { Formatter = new BinaryMessageFormatter() };
queue.ReceiveCompleted += queue_ReceiveCompleted;
queue.BeginReceive();
queue.Send("test message");
Console.ReadLine();
queue.Close();
}
static void queue_ReceiveCompleted(object sender,
ReceiveCompletedEventArgs e)
{
Console.WriteLine("Received message...");
var queue = (MessageQueue)sender;
try
{
var message = queue.EndReceive(e.AsyncResult);
Console.WriteLine("Processing message...");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
queue.BeginReceive();
}
}
}
编辑:只是有一个想法,尝试使用 MessageQueue.Delete(Path) 删除并重新创建队列。它奏效了。我想我的队列不知何故被挤掉了。
New to MSMQ... My local queue never receives my test message. I have verified that Message Queuing and Message Queuing Triggers are running in my Services dialog (Vista Ultimate). Thoughts?
class ConsoleApplication
{
private const string Path = @".\private$\SomeQueue";
static void Main(string[] args)
{
var queue = !MessageQueue.Exists(Path)
? MessageQueue.Create(Path)
: new MessageQueue(Path) { Formatter = new BinaryMessageFormatter() };
queue.ReceiveCompleted += queue_ReceiveCompleted;
queue.BeginReceive();
queue.Send("test message");
Console.ReadLine();
queue.Close();
}
static void queue_ReceiveCompleted(object sender,
ReceiveCompletedEventArgs e)
{
Console.WriteLine("Received message...");
var queue = (MessageQueue)sender;
try
{
var message = queue.EndReceive(e.AsyncResult);
Console.WriteLine("Processing message...");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
queue.BeginReceive();
}
}
}
EDIT: Just had a thought, try deleting and re-creating the queue with MessageQueue.Delete(Path). And it worked. I guess my queue was hosed somehow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试添加
static void queue_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
事件的finally 块。try adding
in finally block of
static void queue_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
event.我怀疑队列本身被破坏了。
更可能的是创建队列和访问队列之间的时间问题。
在专用队列可用之前,MSMQ 必须执行各种操作,例如在 LQS 目录中创建配置文件。
I doubt that the queue itself was broken.
More likely a timing issue between creating the queue and accessing it.
MSMQ has to perform various operations, such as create a config file in the LQS directory, before the private queue is available.
您无法同时访问控制台。尝试执行 thread.Sleep() 并在回调中设置一个布尔值。然后,您可以在布尔值设置后执行 readline 来读取输出。
也许您可能想使用断点和 debug.WriteLine() 来读取写入 Visual Studio 输出窗口的输出。
You can't access the console concurrently. Try doing a thread.Sleep() and set a boolean in your callback. Then you can do a readline after the boolean is set to read your output.
Perhaps you might want to use a breakpoint and the debug.WriteLine() to read output written into the visual studio output window.