Announcement Announcement Module
No announcement yet.
Sharing a RabbitTemplate Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sharing a RabbitTemplate

    Hi All,

    I am putting together a relatively simple demo of Spring AMQP and RabbitMQ.

    After some initialization code has finished, I was going to create several producer threads. At first I was going to let each producer thread instantiate its own RabbitTemplate. But then I thought that I might simply pass to the thread's constructor the template I created in the initialization code.

    Thus, each producer thread and the "main" thread code that comes after init would all be using same template.

    Is this OK, or are there "issues" with such an approach?

    More generally, I have the same question about sharing objects like RabbitAdmin and Exchange.

    Thanks for your help.


  • #2
    As with most Spring strategies RabbitTemplate is thread safe after configuration (so fine to share). Ditto the other things - just don't re-configure them once you start using them, which normally means you are fine if you stick to coding to the interfaces.


    • #3
      Thank you, Dave.