使用RabbitMQ和Apache Camel获取AMQP消息的错误路由密钥
我很难找到骆驼路线的问题。从我所读到的,似乎这可能是我的路由密钥头信息搞砸了,但我不知道如何解决这个问题。另外,这是一个JavaOSGi项目,如果这很重要的话,但是所有的Camel文件目前都是用XML实现的。感谢您的帮助 以下是我想做的:使用RabbitMQ和Apache Camel获取AMQP消息的错误路由密钥,rabbitmq,apache-camel,Rabbitmq,Apache Camel,我很难找到骆驼路线的问题。从我所读到的,似乎这可能是我的路由密钥头信息搞砸了,但我不知道如何解决这个问题。另外,这是一个JavaOSGi项目,如果这很重要的话,但是所有的Camel文件目前都是用XML实现的。感谢您的帮助 以下是我想做的: <!-- The first route creates an object with some info in it and drop it on a rabbitmq exchange called message.added --> <
<!-- The first route creates an object with some info in it and drop it on a rabbitmq
exchange called message.added -->
<route id="directIn">
<from uri="direct:in" />
<bean ref="connector" method="handleIncoming" />
<marshal id="marshal-one" ref="firstObject" />
<to uri="rabbitmq://localhost:5672/me.ex?exchangeType=topic&durable=false&autoDelete=true&routingKey=message.added" />
</route>
<!-- This route listens to message.added, processes the data, creates a new object, and
drops it on a different rabbitmq exchange called message.rest -->
<route id="addedOne">
<from uri="rabbitmq://localhost:5672/me.ex?exchangeType=topic&durable=false&autoDelete=true&routingKey=message.added" />
<unmarshal id="unmarshal-one" ref="firstObject" />
<bean ref="connector" method="processAndConvert" />
<marshal id="marshal-out" ref="secondObject" />
<to uri="rabbitmq://localhost:5672/me.ex?exchangeType=topic&durable=false&autoDelete=true&routingKey=message.rest" />
</route>
似乎“secondObject”在某个点上正在进入“message.added”交换,并被“addedTwo”路由拾取,该路由试图将其封送到“firstObject”中。但是我没有明确告诉它在代码中的任何地方都要这样做-有什么想法吗?在RabbitMQ Camel组件中,
routingKey
端点选项只适用于消费者(
)
生产者必须将其路由密钥明确设置为
之前的消息头。您的addedOne
路线应如下所示:
<route id="addedOne">
<from uri="rabbitmq://localhost:5672/me.ex?exchangeType=topic&durable=false&autoDelete=true&routingKey=message.added" />
<unmarshal id="unmarshal-one" ref="firstObject" />
<bean ref="connector" method="processAndConvert" />
<marshal id="marshal-out" ref="secondObject" />
<setHeader headerName="rabbitmq.ROUTING_KEY">
<constant>message.rest</constant>
</setHeader>
<to uri="rabbitmq://localhost:5672/me.ex?exchangeType=topic&durable=false&autoDelete=true" />
</route>
message.rest
有关更多信息,请参阅。在RabbitMQ Camel组件中,
路由键
端点选项仅适用于消费者(
)
生产者必须将其路由密钥明确设置为
之前的消息头。您的addedOne
路线应如下所示:
<route id="addedOne">
<from uri="rabbitmq://localhost:5672/me.ex?exchangeType=topic&durable=false&autoDelete=true&routingKey=message.added" />
<unmarshal id="unmarshal-one" ref="firstObject" />
<bean ref="connector" method="processAndConvert" />
<marshal id="marshal-out" ref="secondObject" />
<setHeader headerName="rabbitmq.ROUTING_KEY">
<constant>message.rest</constant>
</setHeader>
<to uri="rabbitmq://localhost:5672/me.ex?exchangeType=topic&durable=false&autoDelete=true" />
</route>
message.rest
有关更多信息,请参阅
<route id="addedOne">
<from uri="rabbitmq://localhost:5672/me.ex?exchangeType=topic&durable=false&autoDelete=true&routingKey=message.added" />
<unmarshal id="unmarshal-one" ref="firstObject" />
<bean ref="connector" method="processAndConvert" />
<marshal id="marshal-out" ref="secondObject" />
<setHeader headerName="rabbitmq.ROUTING_KEY">
<constant>message.rest</constant>
</setHeader>
<to uri="rabbitmq://localhost:5672/me.ex?exchangeType=topic&durable=false&autoDelete=true" />
</route>