Using multicast queues in System.Messaging and MSMQ 3.0
Asked Answered
O

1

7

I am trying to use MessageQueues to notify users of an application of data changes using the Multicast feature, but can't get it to work : the workstation that sends the message does receive it, but none of the other running workstations seem to catch the sent message.

Sending messages is done as follows :

Dim sendQueue As New Messaging.MessageQueue("FormatName:MULTICAST=234.1.1.1:8001")
Dim message As New Messaging.Message("message body...")
sendQueue.Send(message)

And receiving them :

Dim receiveQueue As New Messaging.MessageQueue(".\private$\myQ")
receiveQueue.MulticastAddress = "234.1.1.1:8001"
receiveQueue.BeginReceive()

AddHandler receiveQueue.ReceiveCompleted, Sub(sender As Object, e As Messaging.ReceiveCompletedEventArgs)
    ' ... handle message
    receiveQueue.BeginReceive()
End Sub

So I'm obviously missing something, and I can't seem to find any good resources on multicasting with MSMQ 3.0 in .NET.

Also, what is not clear is whether I should use a local queue per workstation, or one single remote queue on a server to multicast messages ? And does using the receive method on multicast messages purge them from the queue?

Any help, hints, tips, suggestions, anything... will be greatly welcome.

On a side note, all workstations are on the same subnet, and all have MSMQ 3.0 installed.

The final word

Well thank you laptop for your help. The issue was actually related to permissions as I discovered while testing your solution with COM objects :

Despite what the Queue properties dialog says, permissions are NOT totally ignored on unauthenticated queues, at least when using multicasting. If you want your queue to receive multicast messages, it must give to 'ANONYMOUS_LOGON' the right to 'Send messages'. Otherwise, multicast messages are just discarded without any notice in event logs or whatsoever (unless I missed something).

On Win7 stations (XP stations seem to do fine, which is what pointed me to the actual problem), queues created through code do not have such permissions, and hence must be manually set after creating the queue :

Dim msgQ = Messaging.MessageQueue.Create(queueName)
msgQ.SetPermissions("ANONYMOUS LOGON",
                    Messaging.MessageQueueAccessRights.WriteMessage)

It would seem that internally, MSMQ uses that account to write multicast messages to unauthenticated queues.

Oilskin answered 21/12, 2011 at 10:30 Comment(8)
Additionnally, capping the network shows that all messages are correctly sent on the multicast address... But it seems that for some reason, the queues associated with the multicast address do not receive the messages sent.Oilskin
have you setup "\private$\myQ" to non-transactional queue. MSMQ 3.0 multicast abilities only work for non-transactional queue.Clamp
Yes, I just double-checked. To sum it up : * Each machine has only one NIC enabled (to ensure this is not related to binding IP issues), and all machines are on the same subnet * Firewall is disabled on all workstations * Each local queue is non-transactionnal, and owned by the active user. Each queue also has its multicast property set to the address mentionned in the post. * Messages DO get sent (checked by monitoring outgoing queues and network traffic), they just don't reach any other queueOilskin
To clarify, the sending machine also has a local queue subscribing to the Multicast address and sent messages arrive in that queue, yes? That indicates the messages are being sent successfully in a way that should be delivered. If that is the case then it is not a programming issue. You mention network capturing shows traffic - are you capturing on the sender or on another machine (preferably the latter)?Twenty
Yes, that's right, but messages never got in any queue, even the one on the sending machine. It's actually a permissions thing... See my original question for the fix...Oilskin
No, my messages are 6 chars long stringsOilskin
Note - receiveQueue.MulticastAdress = "234.1.1.1:8001" (typed wrong above) is only used in queue creation.Twenty
Thanks for the tip... For the typo, well, it is spelled correctly in actual code :)Oilskin
C
2

Could you create the MSMQDestination class and assigned multicast format into it, set the message label and perform sending task using MSMQMessage class

Dim dest As New MSMQDestination
dest.FormatName = "MULTICAST=234.1.1.1:8001"

Dim message As MSMQMessage
message.label ="Test Message"
message.Send DestinationQueue:=dest

FINAL WORD UPDATE I'm glad you relief now. for your issue in other machine, it is a security enhancement to prevent denial of service attack. default msmq queue permission changed in msmq 4.0

Clamp answered 21/12, 2011 at 13:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.