Search code examples
apache-camelactivemq-classicspring-dsl

How to set Queue name from Header value in Apache Camel


Im trying to set activemq queue name from header value but its not happening below is my Spring DSL

<setHeader headerName="x-so-queue-name" id="_setHeader1">
   <xpath resultType="java.lang.String">/Message/@IntObjectName</xpath>
</setHeader>
<log id="_log1" message="x-so-queue-name::: ${header.x-so-queue-name}"/>
<to id="_to1" uri="activemq:queue:${header.x-so-queue-name}"/>

LOGS 16:03:57,601 | INFO | _route1 | x-so-queue-name::: IDC_SO_Refill_IO

header value is printing in the logs but queue name is set to "${header.x-so-queue-name}" why its not retrieving the the value for header, am i doing some thing wrong

enter image description here


Solution

    1. Replace the 'x-so-queue-name' header name with the header named 'CamelJmsDestinationName'

    2. Then in the uri, remove the ${header.x-so-queue-name}.. you can put whatever queue name you want, since the ActiveMQ component will look at the header to determine the destination name. I generally use the below, as a reminder that I'm using dynamic queue naming in the route:

    Reference: Camel JMS Component (search for CamelJmsDestinationName)