我发誓这个代码曾经工作过......
我正在使用此示例中的代码: https://www.codeproject.com/Articles/871746/Implementing-pub-sub-using-MSMQ-in-minutes
using System;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Messaging;
using System.Threading;
namespace MSMQPublisher
{
class Publisher
{
static void Main(string[] args)
{
try
{
string MSMQMulticastAddress = "FormatName:MULTICAST=234.1.1.1:8001";
var messageQueue = MessageQueue.Create(MSMQMulticastAddress, true);
var stopWatch = new Stopwatch();
stopWatch.Start();
for (var i = 0; i < 10; i++)
{
Message msg = new Message(string.Format($"{DateTime.UtcNow.Ticks}: msg:{i} hello world "));
msg.UseDeadLetterQueue = true;
msg.TimeToBeReceived = new TimeSpan(0, 0, 1, 0);
messageQueue.Send(msg);
Console.WriteLine("[MSMQ] Sent");
Thread.Sleep(10);
}
stopWatch.Stop();
Console.WriteLine("====================================================");
Console.WriteLine("[MSMQ] done sending messages in " + stopWatch.ElapsedMilliseconds);
Console.WriteLine("[MSMQ] Sending reset counter to consumers.");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("EXCEPTION: " + ex.Message);
Console.Read();
}
}
}
}
抛出异常:
“无法使用路径FormatName创建队列:MULTICAST = 234.1.1.1:8001。”} System.Exception {System.ArgumentException}
我在几台Windows 10计算机上试过这个。 我尝试设置[HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ MSMQ \ Parameters] “MulticastBindIP”
任何人都可以提出可能的解决方案或指出我正在做的蠢事吗?
由于