In JMS there are Queues and Topics. As I understand it so far queues are best used for producer/consumer scenarios, where as topics can be used for publish/subscribe. However in my scenario I need a way to combine both approaches and create a producer-consumer-observer architecture.
Particularly I have producers which write to some queues and workers, which read from these queues and process the messages in those queues, then write it to a different queue (or topic). Whenever a worker has done a job my GUI should be notified and update its representation of the current system state. Since workers and GUI are different processes I cannot apply a simple observer pattern or notify the GUI directly.
What is the best way to realize this using a combination of queues and/or topics? The GUI should always be notified, but it should never consume anything from a queue?
I would like to solve this with JMS directly and not use any additional technology such as RMI to implement the observer part.
To give a more concrete example:
- I have a queue with packages (
PACKAGEQUEUE
), produced by machine (PackageProducer
) - I have a worker which takes a package from the
PACKAGEQUEUE
adds an address and then writes it to aMAILQUEUE
(AddressWorker
) - Another worker processes the
MAILQUEUE
and sends the packages out by mail (MailWorker
). - After step 2. when a message is written to the
MAILQUEUE
, I want to notify the GUI and update the status of the package. Of course the GUI should not consume the messages in theMAILQUEUE
, only theMailWorker
must consume them.