1

I swear this code used to work .....

I'm using code from this sample: 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();
            }
        }
    }
}

Which throws the exception :

"Cannot create a queue with the path FormatName:MULTICAST=234.1.1.1:8001."} System.Exception {System.ArgumentException}

I've tried this on several Windows 10 Machines. I tried setting [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSMQ\Parameters] "MulticastBindIP"

Can anyone suggest a possible resolution or point out what stupid thing I'm doing?

Thanks

  • HTTP and MulticastSupport are switched on? – Fildor Feb 24 '17 at 15:18
  • If it makes a difference, the example uses `new MessageQueue("FormatName:MULTICAST=234.1.1.1:8001")` not `MessageQueue.Create` – Fildor Feb 24 '17 at 15:19
  • MS sais here: https://msdn.microsoft.com/en-us/library/5yka0xsf(v=vs.110).aspx that create will throw an exception if the queue already exists. Does it? – Fildor Feb 24 '17 at 15:25
  • http://stackoverflow.com/a/28774953/982149 This also hints to that you cannot use MessageQueue.create here. – Fildor Feb 24 '17 at 15:29
  • 3
    Possible duplicate of [How do I send/receive multicast messages using MSMQ?](http://stackoverflow.com/questions/28773194/how-do-i-send-receive-multicast-messages-using-msmq) – Fildor Feb 24 '17 at 15:31
  • Thanks Fildor - I've tried both syntaxes and get the same error. It does look like it created the QUEUE so I tried ignoring the exception and message seem to get to the queue but then immediately disappear even though no one is reading them. I tried manually setting a long TimeToBeReceived but they still disappear. Thanks . – Joe Stagner Feb 24 '17 at 16:01

0 Answers0