【发布时间】:2022-12-20 04:34:24
【问题描述】:
我正在开发一个使用 java 消息服务 (JMS) 的项目,它使用 activemq 连接工厂实现。
现在我想使用 spring-cloud-starter-sleuth 来检测应用程序以进行跟踪。但是我无法做到这一点,因为我在启动应用程序时遇到异常 -
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.activemq.pool.PooledConnectionFactory]: Factory method 'pooledConnectionFactory' threw exception; nested exception is java.lang.IllegalStateException: @Bean method JmsConfiguration.senderActiveMQConnectionFactory called as bean reference for type [org.apache.activemq.ActiveMQConnectionFactory] but overridden by non-compatible bean instance of type [org.springframework.cloud.sleuth.instrument.messaging.LazyTopicConnectionFactory]. Overriding bean of same name declared in: class path resource [com/demo/appconfig/JmsConfiguration.class]
以下是我使用的连接工厂 bean:
// ***** sender configuration
@Bean
public ActiveMQConnectionFactory senderActiveMQConnectionFactory() {
ActiveMQConnectionFactory activeMQConnectionFactory =
new ActiveMQConnectionFactory();
activeMQConnectionFactory.setBrokerURL(brokerUrl);
activeMQConnectionFactory.setUseAsyncSend(useAsyncSend);
return activeMQConnectionFactory;
}
@Bean
public PooledConnectionFactory pooledConnectionFactory() {
return new org.apache.activemq.pool.PooledConnectionFactory(
senderActiveMQConnectionFactory());
}
@Bean
public JmsTemplate jmsTemplate() {
JmsTemplate jmsTemplate = new JmsTemplate(pooledConnectionFactory());
jmsTemplate.setMessageConverter(messageConverter());
return jmsTemplate;
}
我已经尝试了spring-cloud-starter-sleuth 的所有发行版本以及最新版本,但仍然遇到同样的问题。我该如何处理这个问题?
更新:根据https://github.com/spring-cloud/spring-cloud-sleuth/issues/1324中的评论之一 我们需要通过属性禁用 jms 跟踪,并手动检测连接,如 Brave 的自述文件https://github.com/openzipkin/brave/tree/master/instrumentation/jms 所示 但我仍然没有从 brave 的自述文件中获得足够的信息。如何在我的 spring boot 应用程序中手动使用 brave instrumentation?
【问题讨论】:
标签: spring spring-boot spring-jms spring-cloud-sleuth zipkin