3
votes

I would like to create a parametrized endpoint to send messages to JMS queue depending on content of the message, say e.g. MY_QUEUE. The endpoint uri should thus look like

jms:/MY_QUEUE?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.DestinationType=queue

I created and endpoint template like this:

<template xmlns="http://ws.apache.org/ns/synapse" name="TM_out_endpoint_template">
   <axis2ns158:parameter xmlns:axis2ns158="http://ws.apache.org/ns/synapse" name="queue"></axis2ns158:parameter>
   <endpoint name="$name">
      <address uri="jms:/$queue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.DestinationType=queue">
         <suspendOnFailure>
            <progressionFactor>1.0</progressionFactor>
         </suspendOnFailure>
         <markForSuspension>
            <retriesBeforeSuspension>0</retriesBeforeSuspension>
            <retryDelay>0</retryDelay>
         </markForSuspension>
      </address>
   </endpoint>
</template>

However like this the $queue parameter won't get processed. If I substitute the whole URI, it works, but I would like to keep the rest of the URI in the template rather than to pass them from a calling sequence. In short I only want to pass the queue name. How can I concat a param with a string within the endpoint template? E.g. jms:/${queue}?transport... or something. Is there a way?

1

1 Answers

1
votes

This is happening because, $ in $queue parameter get ignored during template rendering because of the / prior to that. So you have to populate the queue name with jms:/ prefix.

This is the modified version of your template.

<template xmlns="http://ws.apache.org/ns/synapse" name="TM_out_endpoint_template">
   <axis2ns158:parameter xmlns:axis2ns158="http://ws.apache.org/ns/synapse" name="queue"></axis2ns158:parameter>
   <endpoint name="$name">
      <address uri="$queue?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616&transport.jms.DestinationType=queue">
         <suspendOnFailure>
            <progressionFactor>1.0</progressionFactor>
         </suspendOnFailure>
         <markForSuspension>
            <retriesBeforeSuspension>0</retriesBeforeSuspension>
            <retryDelay>0</retryDelay>
         </markForSuspension>
      </address>
   </endpoint>
</template>