Distributed Message Service RabbitMQ

Connection and Channel

2024-06-27 06:58:19

Each connection uses approximately 100 KB of memory (or more if TLS is used), and thousands of connections can result in high RabbitMQ load and, in extreme cases, memory overflow. The AMQP protocol introduces the concept of channel, where there can be multiple channels in a connection. The connection is long-lived, and the handshake process of the AMQP connection is more complicated, requiring at least 7 TCP packets (or more if TLS is used). It is easier to open and close channels than connections, but it is recommended that channels also be set up to be long-lived. For example, you should reuse the same channel for each producer thread and not open the channel every time you produce. Best practice is to reuse connections and multiplex connections and channels between threads.

Spring AMQP thread pool is recommended: ConnectionFactory is a connection factory defined by Spring AMQP, responsible for creating connections


52_yyECO69yu