Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is ActiveMQ thread safe?

We would like to run our cms::MessageConsumer and cms::MessageProducer on different threads of the same process.

How do we do this safely?

Would having two cms::Connection objects and two cms::Session objects, one each for consumer and producer, be sufficient to guarantee safety? Is this necessary?

Is there shared state between objects at the static library level that would prevent this type of usage?

like image 804
ThomasMcLeod Avatar asked Dec 16 '22 16:12

ThomasMcLeod


1 Answers

You should read the JMS v1.1 specification, it calls out clearly which objects are valid to use in multiple threads and which are not. Namely the Session, MessageConsumer and MessageProducer are considered unsafe to share amongst threads. We generally try to make them as thread safe as we can but there are certainly ways in which you can get yourself into trouble. Its generally a good idea to use a single session in each thread and in general its a good idea to use a session for each MessageConsumer / MessageProducer since the Session contains a single dispatch thread which means that a session with many consumers must share its dispatch thread for sending messages on to each consumer which can lower latency depending on the scenario.

like image 104
Tim Bish Avatar answered Dec 28 '22 22:12

Tim Bish