我们使用 Spring AMQP 客户端连接到我们的 RabbitMQ,我们的 Spring 配置定义为
<bean id="nativeCF" class="com.rabbitmq.client.ConnectionFactory" p:connection-timeout="#{msgProps['messaging.amqp.connection.timeout.millis']?:30000}"
p:socket-factory-ref="rabbitSslSocketFactory" p:automatic-recovery-enabled="true" p:topologyRecoveryEnabled="false"/>
<rabbit:connection-factory id="connectionFactory" host="#{msgProps['messaging.amqp.host']}"
username="#{msgProps['messaging.amqp.username']}" password="#{propertyEncryptor.decrypt(msgProps['messaging.amqp.password'])}"
port="#{msgProps['messaging.amqp.port']}" requested-heartbeat="#{msgProps['messaging.amqp.heartbeat']?:600}"
channel-cache-size="#{msgProps['messaging.amqp.channel.cache.size']?:150}" connection-factory="nativeCF"/>
- nativeCF 指向基本的 Java 客户端实现 ConnectionFactory。当我调试代码时,我看到自动连接的connectionFactory是(org.springframework.amqp.rabbit.connectionCachingConnectionFactory)
我想覆盖 amqp.rabbit.CachingConnectionFactory 并在配置中 Autowiring 它。 想知道如何继续。
最佳答案
为什么需要这样做?如果直接使用原生连接工厂,你将无法获得Spring提供的功能,那为什么还要使用Spring呢?
也就是说,只要您使用正确的类型声明 Autowiring 变量,您就能够注入(inject) native 连接工厂。
使用 Spring 的 native 客户端自动恢复没有任何好处; Spring AMQP 拥有(并且一直拥有)自己的恢复机制,该机制早于 amqp-client 恢复。
关于java - 覆盖默认的 org.springframework.amqp.rabbit.connection.CachingConnectionFactory 实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33507379/