0

What is the best approach to create a long lived publisher in rabbitmq? The goal is to use the same producer for multiple messages in different classes. I want to avoid creating a new connection and new channel for each message.

Ni12N
  • 123
  • 9

2 Answers2

0

I want to avoid creating a new connection and new channel for each message.

Did you try just not doing that, and keeping the old connection and corresponding channel alive? You can create a helper/singleton class for that. As for the closure of both channel and connection, you'd probably need to override finalize for that. See this topic for more info on destructors

Community
  • 1
  • 1
CptBartender
  • 1,235
  • 8
  • 22
0

I suggest using IOC to handle this for you. Setup the IConnection as a singleton (see this post for help with that https://stackoverflow.com/a/30032001/1173800) and then each time you instantiate your IProducer it will handle re-using the connection for you.

Community
  • 1
  • 1
jhilden
  • 12,207
  • 5
  • 53
  • 76