0

So i am trying to use ActiveMQ within my java project (I never used anything like this before but I've read about how it works).

The application runs on 5 different nodes and on each of them are created the messages that should be send into the same queue.

Here is how I think it should work : I have a class which creates these messages; these messages are created in any of those nodes; so this class works as a thread and should be "the producer", sending every message to the same queue.(therefore I have multiple producers) The consumer class runs always on the same node.

Would this approach work for me? Would the queue be thread safe?

Georgiana_M
  • 47
  • 1
  • 7

1 Answers1

0

Yes, your approach should work without any problem. All message brokers support multiple concurrent producers sending messages to the same queue. There should be no thread safety concerns.

Justin Bertram
  • 29,372
  • 4
  • 21
  • 43
  • From what I've read I assume it's safe to reuse the same connection instead of opening/closing each time one of the producers wants to send a messsage. But what about the session? My application runs on 5 nodes so there are 5 different threads wanting to access the same queue. So each node should have a session – Georgiana_M Dec 03 '18 at 10:09
  • It's not only possible to share connections on a particularly client, it's highly encouraged. Opening a connection for every message sent is an anti-pattern. The session can & should be re-used as well, but it's not as important. One key here is that a JMS session is not thread-safe so should not be used by multiple threads concurrently. Client resources can only be shared by clients in the same JVM so each node will need to have it's own set of resources. – Justin Bertram Dec 03 '18 at 14:13