Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using multicast queues in System.Messaging and MSMQ 3.0

Tags:

.net

vb.net

msmq

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.

like image 866
T. Fabre Avatar asked Dec 21 '11 10:12

T. Fabre


1 Answers

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

like image 140
Turbot Avatar answered Oct 05 '22 02:10

Turbot