当前位置: 代码迷 >> 综合 >> Spring AMQP 中CachingConnectionFactory应该配置几个?
  详细解决方案

Spring AMQP 中CachingConnectionFactory应该配置几个?

热度:42   发布时间:2024-02-09 14:42:26.0

摘自官方:

  When the application is configured with a single CachingConnectionFactory, as it is by default with Spring Boot auto-configuration, the application stops working when the connection is blocked by the Broker. And when it is blocked by the Broker, any of its clients stop to work. If we have producers and consumers in the same application, we may end up with a deadlock when producers are blocking the connection (because there are no resources on the Broker any more) and consumers cannot free them (because the connection is blocked). To mitigate the problem, we suggest having one more separate CachingConnectionFactory instance with the same options?—?one for producers and one for consumers. A separate CachingConnectionFactory is not possible for transactional producers that execute on a consumer thread, since they should reuse the Channel associated with the consumer transactions.

 当应用程序配置为单个CachingConnectionFactory时(默认情况下是springboot自动配置),一旦连接在broker发生阻塞,应用程序会停止工作。当这种情况发生时,所有client都会停止工作。

如果生产者和消费者在同一个应用中,当一个生产者被broker阻塞,而消费者又无法释放生产者,会导致死锁。为了缓解这个问题,建议再创建一个具有相同的配置的单独的CachingConnectionFactory实例,一个用于生产者,一个用于消费者。这样,即使生产者链接发生阻塞,不会影响消费者的链接。

  相关解决方案