gpt4 book ai didi

java - 覆盖默认的 org.springframework.amqp.rabbit.connection.CachingConnectionFactory 实现

转载 作者:太空宇宙 更新时间:2023-11-04 13:16:08 24 4
gpt4 key购买 nike

我们使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com