Reputation: 1305
I would like to create a RabbitMQ publisher that might be called from different threads.
Based on the RabbitMQ best practice i should not allow usages of the same channel in different threads so sharing this channel in multiple instances of the publisher will cause issues.
The only solution i can think of is having a manager thread with an inner queue that implements an internal producer-consumer with a single consumer existing only in that thread.
Is there an easier way? would like to avoid synchronization as much as possible for obvious reasons, this solution does not allow that.
Upvotes: 0
Views: 1084
Reputation: 96
The solution you suggest is OK. You can also have a look at Spring AMQP. It provides a thread-safe RabbitTemplate
that uses channel pooling under the covers.
Upvotes: 1