views:

66

answers:

1

I have a question about Producer/consumer Design pattern , in fact my situation is :I have One class that produce multiple types of messages (notifications) and multiple consumers who consume those messages.

The complication is my Producer produce different types of messages and my consumers consume those messages .

So what is the best implementation of this situation? Is the Producer/Consumer design-pattern the best solution of this situation?

A: 

I think there are two independent problems here. One is getting a "message" object across. That is a producer/consumer problem, though if you want reliability you need to consider a variety of issues like threading, recovery, etc. If you actually do this between multiple machines, do yourself a favour and use an existing framework like JMS.

Separately from that is the problem of handling different types of messages. Usually you would have some type hierarchy of messages all subtyping a common "Message" ancesor. I'm not sure about the semantics of your message, but something along the lines of the command pattern might be a good fit.

You really need to clarify your question more for us to be able to provide better advice.

Uri
To clarify more those messages are totally different . I have a trading application who connect to a broker. This broker give me a lot of prices (this is the first type of message) and give execution report of trades(this is another type).
Zakaria
Those consumers are executed locally(Threads) and that to handle several markets in parallel.
Zakaria