MSMQ 消息多播:无法在不同机器上接收消息
MSMQ Message Multicast: Unable to receive messages on different machine
我想使用 MSMQ 多播功能创建发布者和订阅者模型。
我已经按照 link 中的答案进行操作,但没有成功 MSMQ - Cannot receive from Multicast queues
在本地机器上发送和接收消息。
发件人:
using (var helloQueue = new MessageQueue("FormatName:MULTICAST=234.1.1.1:8001"))
{
while (true)
{
var stopWatch = new Stopwatch();
stopWatch.Start();
for (var i = 0; i < 1000; i++)
{
SendMessage(helloQueue,
string.Format("{0}: msg:{1} hello world ", DateTime.UtcNow.Ticks, i));
}
stopWatch.Stop();
Console.ReadLine();
Console.WriteLine("====================================================");
Console.WriteLine("[MSMQ] done sending 1000 messages in " + stopWatch.ElapsedMilliseconds);
Console.WriteLine("[MSMQ] Sending reset counter to consumers.");
SendMessage(helloQueue, "reset");
Console.ReadLine();
}
}
收件人:
int messagesReceived = 0;
var messages = new Queue<string>(5000);
var filePath = typeof(Subscriber).FullName + ".txt";
var path = @".\private$\hello-queue";
using (var helloQueue = new MessageQueue(path))
{
helloQueue.MulticastAddress = "234.1.1.1:8001";
while (true)
{
var message = helloQueue.Receive();
if (message == null)
return;
var reader = new StreamReader(message.BodyStream);
var body = reader.ReadToEnd();
messagesReceived += 1;
messages.Enqueue(body);
Console.WriteLine(" [MSMQ] {0} Received {1}", messagesReceived, body);
if (string.CompareOrdinal("reset", body) == 0)
{
messagesReceived = 0;
File.WriteAllText(filePath, body);
messages.Clear();
}
}
}
我在注册表中添加了事件日志中显示 IP 的 multicastbind 密钥(对此不确定)。
我们在队列中指定的 MulticastAddress,它是特定的东西还是我们可以使用指定范围内的任何东西?
只需更改端口号即可解决此问题。休息的很好。
我想使用 MSMQ 多播功能创建发布者和订阅者模型。 我已经按照 link 中的答案进行操作,但没有成功 MSMQ - Cannot receive from Multicast queues 在本地机器上发送和接收消息。
发件人:
using (var helloQueue = new MessageQueue("FormatName:MULTICAST=234.1.1.1:8001"))
{
while (true)
{
var stopWatch = new Stopwatch();
stopWatch.Start();
for (var i = 0; i < 1000; i++)
{
SendMessage(helloQueue,
string.Format("{0}: msg:{1} hello world ", DateTime.UtcNow.Ticks, i));
}
stopWatch.Stop();
Console.ReadLine();
Console.WriteLine("====================================================");
Console.WriteLine("[MSMQ] done sending 1000 messages in " + stopWatch.ElapsedMilliseconds);
Console.WriteLine("[MSMQ] Sending reset counter to consumers.");
SendMessage(helloQueue, "reset");
Console.ReadLine();
}
}
收件人:
int messagesReceived = 0;
var messages = new Queue<string>(5000);
var filePath = typeof(Subscriber).FullName + ".txt";
var path = @".\private$\hello-queue";
using (var helloQueue = new MessageQueue(path))
{
helloQueue.MulticastAddress = "234.1.1.1:8001";
while (true)
{
var message = helloQueue.Receive();
if (message == null)
return;
var reader = new StreamReader(message.BodyStream);
var body = reader.ReadToEnd();
messagesReceived += 1;
messages.Enqueue(body);
Console.WriteLine(" [MSMQ] {0} Received {1}", messagesReceived, body);
if (string.CompareOrdinal("reset", body) == 0)
{
messagesReceived = 0;
File.WriteAllText(filePath, body);
messages.Clear();
}
}
}
我在注册表中添加了事件日志中显示 IP 的 multicastbind 密钥(对此不确定)。 我们在队列中指定的 MulticastAddress,它是特定的东西还是我们可以使用指定范围内的任何东西?
只需更改端口号即可解决此问题。休息的很好。