繁体   English   中英

MSMQ消息多播:无法在其他计算机上接收消息

[英]MSMQ Message Multicast: Unable to receive messages on different machine

我想使用MSMQ组播功能创建发布者和订阅者模型。 我已经按照链接中的答案进行操作,但未成功。MSMQ-无法从多播队列接收消息正在本地计算机中发送和接收消息。

发件人:

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多播绑定(对此不确定)。 我们在队列中指定的MulticastAddress是特定的还是可以使用指定范围内的任何内容?

只需更改端口号即可解决此问题。 休息很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM