In general, it is not recommended to open and close connections and channels for each message. Connections are durable, and resources are required to open and close them. For channels, they share a TCP connection with the connection, so they are lighter, but they will still consume memory and, of course, should not remain open after using them.
It is recommended to have a channel per stream and a channel for each consumer. But for publishing, it’s quite normal to use the same channel. But keep in mind that depending on the operations, the protocol can kill the channel in certain situations (for example, checking the existence of a queue), so prepare for this. There are also soft (customizable) and hard (usually 65535) restrictions on the maximum number of channels on many client implementations.
So, to summarize, depending on your use case, use one to several connections, open channels when you need them, and share them when it makes sense, but don't forget to close them when you're done.
The rabbitmq documentation explains the nature of the connections and channels (end of document). And the accepted answer to this question has good information on this issue.
source share