Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camel not publishing to RabbitMQ queue

I have a simple route defined in a routeContext in Camel (this route will be used in multiple routes).

    <route id="sendToRabbitQueue">
        <from uri="direct:sendToQueue" />
        <convertBodyTo type="java.lang.String"/>
        <setHeader headerName="rabbitmq.ROUTING_KEY">
            <constant>my.routing.key</constant>
        </setHeader>
        <to uri="ref:genericRabbitEndpoint"/>
    </route>

And I have an endpoint (defined in an endpoints file)

    <endpoint id="genericRabbitEndpoint" uri="rabbitmq://${rabbitmq.host}:${rabbitmq.port}/${rabbitmq.exchange.name}">
        <camel:property key="autoDelete" value="false" />
        <camel:property key="connectionFactory" value="#rabbitConnectionFactory" />
    </endpoint>

Yes - I have seen the http://camel.apache.org/rabbitmq.html page - that's where I got the idea to set the header on the exchange. However no message is being published on the queue. I'm clearly overlooking something and any help would be appreciated.

like image 684
Airomega Avatar asked Sep 03 '15 16:09

Airomega


1 Answers

So this seems like a bit of a gotcha and the answer relates to part of the route I didn't include in the question because I didn't think it was relevant.

The route starts at a RabbitMQ endpoint (not included above). As a result the exchange has some RabbitMQ headers set when it arrives:

  • rabbitmq.ROUTING_KEY
  • rabbitmq.EXCHANGE_NAME
  • rabbitmq.DELIVERY_TAG

These headers are used across the life of the route and appear to override the values when I try to publish at a different RabbitMQ endpoint. The way I've fixed is by introducing a bean which strips the headers out. Not ideal behaviour in my opinion...

public void stripRabbitHeaders(@Headers Map headers)
{
    headers.remove("rabbitmq.ROUTING_KEY");
    headers.remove("rabbitmq.DELIVERY_TAG");
    headers.remove("rabbitmq.EXCHANGE_NAME");
}
like image 174
Airomega Avatar answered Oct 05 '22 13:10

Airomega