簡體   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