views:

927

answers:

1

Is it possible to have multiple listeners to messages carried by MSMQ?

WCF appears to frame everything in terms of services, making communication a point-to-point affair. I want to use a message queue to buffer incoming traffic for another process that records the logs in a database.

There can be be any number of other processes interested in monitoring incoming traffic, and this positively begs for Observer pattern, but I can't see how to express Observer pattern, at least not using MSMQ via WCF.

Can anyone advise me on this?


Some background on why I care, which may also serve to illustrate the problem: I have a Windows service that accepts connection requests from little black boxes in the field. It sets up sockets and the black boxes send messages describing events annotated with GPS locations in time and space.

I parse message packets from the socket stream and send them via MSMQ to another process that filters duplicates and writes the packets into a database table.

There is any amount of post-processing that would benefit from incremental computation in response to incoming traffic, and user tools perform user notification also in response to incoming traffic.

So, I'd really like to have one process sending the messages, and several receiving them. One of these receivers is responsible for parsing the packet contents and transcribing the message into a database; this is an obvious candidate for the responsibility of finally removing the message from the queue, but there is the question of how to ensure this is the last handler to process the message.

+3  A: 

I don't believe MSMQ is appropriately designed to handle this situation by itself. There are only 2 things you can do to a message - Peek() or Get(). AFAIK, there isn't a good way to track whether a message had been processed by all handlers.

What might work is to have your process that transcribes the message be the Observee, and publish the message (perhaps using the .NET Event architecture) to all interested Observers before transcribing the message and writing to the database. This would provide a guarantee that all interested Observers saw the message, and the message gets written to the DB appropriately.

Harper Shelby
Harper, this is exactly what I have ended up doing. I've created two interfaces, IPublisher and ISubscriber, and a duplex binding. The logger is the MSMQ endpoint, and after the data is safely in the database it notifies any subscribers.
Peter Wone
hein Peter, Could you send me your code ? I need to develope somthing similar...
Paul