0

I want to create a simple publish subscribe setup where my publisher keeps broadcasting messages whether there are 0,1 or more subscribers and subscribers came and go when they need and read the latest messages. I don't want older messages to be read by the subscribers. For ex. if the publisher comes online and starts publishing, lets say it publishes 100 messages while there are currently no subscribers I want those messages to disappear. If a subscriber 1 comes online and 101st message is published that will be the first message seen by subscriber 1. This appears to be how multicast msmq works but the problem I am running into is that while my publisher is running, the \System32\msmq\storage will rapidly fill up with 4mb files, they have some autoincremented names, in my case usually r000001a.mq,r000001b.mq, or something similar. I don't know how to manage how these files are created, there are no messages in my outgoing multicast queue, and these files show up whether or not I have any subscribers listening. The only way I can clear these files is by restarting the message queuing service.

The code I'm using to publish these files is

using (var queue = new msmq.MessageQueue
    ("FormatName:MULTICAST=234.1.1.2:8001"))
{
    var message = new msmq.Message();
    message.BodyStream = snsData.ToJsonStream();
    message.Label = snsData.GetMessageType();
    queue.Send(message);
}

Is there any way I can programatically control how these .mq files get created? They will rapidly use up the allowable queue storage.

Thank you,

1 Answers1

0

R*.MQ files are used to store express messages. It's just for efficiency, not recovery, as they are purged on a service restart as you are finding out. I would use Performance Monitor to find out which queue the messages are in - they have to be in a queue somewhere. Once you know the queue, you can work backwards - if it's a custom queue, check your code; if it's a system queue, then that would be interesting.

John Breakwell
  • 4,667
  • 20
  • 25
  • 1
    Thank you, it looks like the issue was wrapping my multicast queue in a using statement and then repeatedly calling that function faster than the queues can be disposed or deleted. Once I changed the using (var queue = new msmq.MessageQueue ("FormatName:MULTICAST=234.1.1.2:8001")) to hold on to my queue and just dispose of it manually when no longer needed I noticed only a single .mq file would be created. – Krzysiek Derkowski Jul 11 '17 at 15:05