我有一个spring应用程序,它使用camel来设置从队列中使用的路由。 我使用rabbitmq作为消息代理。 现在的问题是,如果rabbitmq代理崩溃,连接不会自动恢复。 我尝试启用automaticRecoveryEnabled。但我得到noSuchMethodError。 我将展示用于创建连接的代码。
<camelContext xmlns="http://camel.apache.org/schema/spring">
<propertyPlaceholder id="properties" location="file:data/rabbitmq/rabbitmq.properties"/>
<route>
<from uri="rabbitmq://{{mete.rabbitmq.host}}:{{mete.rabbitmq.port}}/{{mete.rabbitmq.exchange}}
?queue={{mete.rabbitmq.queue}}&username={{mete.rabbitmq.username}}
&password={{mete.rabbitmq.password}}&exchangeType={{mee.rabbitmq.exchange.type}}
&queueArgsConfigurer=#myArgs&autoDelete=false&automaticRecoveryEnabled=true&networkRecoveryInterval=654&requestedHeartbeat=987"/>
<to uri="stream:out"/>
<process ref="myProcessor"/>
</route>
</camelContext>
下面是堆栈跟踪
Exception in thread "main" java.lang.NoSuchMethodError: com.rabbitmq.client.ConnectionFactory.setAutomaticRecoveryEnabled(Z)V
at org.apache.camel.component.rabbitmq.RabbitMQEndpoint.getOrCreateConnectionFactory(RabbitMQEndpoint.java:278)
at org.apache.camel.component.rabbitmq.RabbitMQEndpoint.connect(RabbitMQEndpoint.java:195)
at org.apache.camel.component.rabbitmq.RabbitMQConsumer.openConnection(RabbitMQConsumer.java:68)
at org.apache.camel.component.rabbitmq.RabbitMQConsumer.doStart(RabbitMQConsumer.java:118)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:2869)
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRouteConsumers(DefaultCamelContext.java:3163)
at org.apache.camel.impl.DefaultCamelContext.doStartRouteConsumers(DefaultCamelContext.java:3099)
at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3029)
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:2797)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:2653)
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:167)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2467)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:2463)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:2486)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:2463)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:2432)
at org.apache.camel.spring.SpringCamelContext.maybeStart(SpringCamelContext.java:255)
at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(SpringCamelContext.java:121)
at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(CamelContextFactoryBean.java:332)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:303)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:911)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:428)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
at rabbitmqClient.AbstractConsumer.openAMQPConnection(AbstractConsumer.java:77)
at rabbitmqClient.ConsumerPoolExecutor.startConsumer(ConsumerPoolExecutor.java:122)
at medagate.MedagateContext.main(MedagateContext.java:15)
答案 0 :(得分:0)
由于amqp-client依赖性而发生错误。 当版本从2.8.4更改为3.5.1时,代码工作正常。 新的依赖是:
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>3.5.1</version>
</dependency>