声明死信交换时,无法创建Camel RabbitMQ端点

时间:2016-04-04 11:10:16

标签: spring-boot apache-camel rabbitmq

我在使用Camel创建RabbitMQ端点时遇到问题。只有当我根据camel documentation声明一个死信消息交换选项时,才会出现此问题。这是我创建端点的URN:

rabbitmq://localhost/com.mydomain.inbound.exhange?deadLetterExchange=dead.msgs

当我省略deadLetterExchange选项时,一切都很好但是一旦我包含它,我得到以下(不是非常有帮助)的异常:

  

引起:java.lang.NullPointerException       在com.rabbitmq.client.impl.ChannelN.validateQueueNameLength(ChannelN.java:1244)〜[amqp-client-3.6.1.jar:?]       在com.rabbitmq.client.impl.ChannelN.queueDeclare(ChannelN.java:843)〜[amqp-client-3.6.1.jar:?]       在com.rabbitmq.client.impl.ChannelN.queueDeclare(ChannelN.java:61)〜[amqp-client-3.6.1.jar:?]       在org.apache.camel.component.rabbitmq.RabbitMQDeclareSupport.declareAndBindQueue(RabbitMQDeclareSupport.java:96)〜[camel-rabbitmq-2.17.0.jar:2.17.0]       在org.apache.camel.component.rabbitmq.RabbitMQDeclareSupport.declareAndBindDeadLetterExchangeWithQueue(RabbitMQDeclareSupport.java:43)〜[camel-rabbitmq-2.17.0.jar:2.17.0]       在org.apache.camel.component.rabbitmq.RabbitMQDeclareSupport.declareAndBindExchangesAndQueuesUsing(RabbitMQDeclareSupport.java:35)〜[camel-rabbitmq-2.17.0.jar:2.17.0]       在org.apache.camel.component.rabbitmq.RabbitMQEndpoint.declareExchangeAndQueue(RabbitMQEndpoint.java:222)〜[camel-rabbitmq-2.17.0.jar:2.17.0]       在org.apache.camel.component.rabbitmq.RabbitConsumer.openChannel(RabbitConsumer.java:288)〜[camel-rabbitmq-2.17.0.jar:2.17.0]       在org.apache.camel.component.rabbitmq.RabbitConsumer。(RabbitConsumer.java:57)〜[camel-rabbitmq-2.17.0.jar:2.17.0]       在org.apache.camel.component.rabbitmq.RabbitMQConsumer.createConsumer(RabbitMQConsumer.java:108)〜[camel-rabbitmq-2.17.0.jar:2.17.0]       在org.apache.camel.component.rabbitmq.RabbitMQConsumer.startConsumers(RabbitMQConsumer.java:90)〜[camel-rabbitmq-2.17.0.jar:2.17.0]       在org.apache.camel.component.rabbitmq.RabbitMQConsumer.doStart(RabbitMQConsumer.java:160)〜[camel-rabbitmq-2.17.0.jar:2.17.0]       在org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)〜[camel-core-2.17.0.jar:2.17.0]       在org.apache.camel.impl.DefaultCamelContext.startService(DefaultCamelContext.java:3269)~ [camel-core-2.17.0.jar:2.17.0]       at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRouteConsumers(DefaultCamelContext.java:3563)~ [camel-core-2.17.0.jar:2.17.0]       在org.apache.camel.impl.DefaultCamelContext.doStartRouteConsumers   ....

请注意,我还尝试手动创建交换和队列,希望这可能有效,但没有运气。

其他信息:

  • camel-spring-boot-starter(2.17.0)
  • camel-rabbitmq(2.17.0)

1 个答案:

答案 0 :(得分:1)

尝试添加HTMLElement[]选项 -

deadLetterQueue

我还必须为uri添加更多选项以使其工作。我添加了

  • deadLetterExchangeType
  • queueArgsConfigurer

queueArgsConfigurer是rabbitmq://localhost/com.mydomain.inbound.exhange?deadLetterExchange=dead.msgs&deadLetterQueue=my.dead.letter.queue

的实现
org.apache.camel.component.rabbitmq.ArgsConfigurer

我是一个Spring应用程序,因此在bean工厂中创建了class MyQueueArgs implements ArgsConfigurer { void configurArgs(Map<String, Object> args) { //misspelling!! args.put("x-dead-letter-exchange", "my.dead.letter") args.put("x-dead-letter-routing-key", "my.dead.letter.key") } } (见下文)。

所以,完整的uri就像这样 -

myArgs

我可能不需要在uri和ArgsConfigurer实现中指定死信交换。

有关ArgsConfigurer的更多信息,这个Camel问题可能有所帮助 - #8457

我不得不查看源代码来解决这个问题。 doc中缺少的是依赖关系的定义。有一些选项,尤其是死信交换,如果指定了另一个选项,它们将成为强制性的。这就是你收到错误的原因。请查看RabbitMQDeclareSupport中的rabbitmq://hostname/exchangeName?routingKey=$routingKey&vhost=virtualHostname&exchangeType=exType&autoDelete=false&queue=my.queue&deadLetterExchange=my.dead.letter&deadLetterExchangeType=dlExType&deadLetterQueue=my.dead.letter.queue&queueArgsConfigurer=#myArgs

修改

简化了我的回答 - 我最终删除了populateQueueArgumentsFromDeadLetterExchange实现。我跟着这个 -

ArgsConfigurer