Pregunta

There are two threads in my application - one that asynchronously reads the messages from MQ queue and send them to the processing unit and a second that retrieves information from processing unit and puts the related messages on a sender queue. The problem is, next messages is retrieved and send to the processing unit before the previous message output thread has finished and this is not correct from application point of view. Since the messages may be found on queue at any time to be processed, it is not desirable to read messages synchronously.

I know that I could introduce another queue to keep messages until ready to be processed but are there any MQ setup-related solutions that I could use instead? It seems to me like a very common setup.

Thank you in advance for advice/help.

¿Fue útil?

Solución

This is basically a synchronisation problem. I would have setup an signalling mechanism where message listener sends the message received from MQ to processing unit and waits on an event. The output thread after sending the message to an output queue signals the event. Once signalled the message listener waits for the next message from queue.

Otros consejos

I could understand the question to some extent ... It looks like all you want to do to is to hold the message listener for sometime until another activity is completed. The message listener can use a selector which gets messages which have a property state=READY. When the output thread completes it can get a message from queue and set the state to READY. By default if this property is not set on the message the message listener won't pick that message.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top