Camel jms: How to set replyTo - jms

this is the route:
<from uri="timer://tick-tock-timer?period=50000" />
<transform>
<simple>Message at ${date:now:yyyy-MM-dd HH:mm:ss}</simple>
</transform>
<to uri="activemq:queue:inbox" pattern="InOut" />
</route>
<route id="consumer14">
<from uri="activemq:queue:inbox"/>
<convertBodyTo type="java.lang.String"/>
<transform>
<simple>${in.body}
</simple>
</transform>
<log message="${body}"/>
</route>
i try to send reply indicates that the message was received and i dont know where it should be.
How can i do this ?

You can read about the replyTo option at the Camel JMS component doc page:
http://camel.apache.org/jms
You can tell what the replyTo should be
<to uri="activemq:queue:inbox?replyTo=foo" pattern="InOut" />
Then the 2nd route will automatic use that when sending back the reply message when its at the end of the route.
Also pay attention to the various kind of reply queues, such as temporary, shared or exclusive.

Related

Retrieve clob data using apache camel

I am polling clob column using apache camel as below.
<route>
<from uri="timer://timer1?period=2m" />
<setBody>
<simple>
SELECT CLOB_COLUMN FROM TABLE WHERE STATUS=1
</simple>
</setBody>
<to uri="jdbc:dataSource?outputType=StreamList" />
<split streaming="true">
<simple>${body}</simple>
<setProperty name="myProperty">
<simple>${body[CLOB_COLUMN]}</simple>
</setProperty>
<to uri="direct:processing"/>
</split>
</route>
Body of processing route shows like oracle.sql.clob#123456. How can I convert that value to String format.
Camel 2.23 version used to give value as String format but after upgraded to 3.16, its giving clob value.

JMS Selector for messages having an underscore in one header with Camel and Blueprint

I need to cleanup some messages in a JMS queue (ActiveMQ) where some of the message header contains an underscore.
Some example
Message 1:
header MyObject=urn:sap:order:ID1234
body = <some xml>
Message 2:
header MyObject=urn:sap:order:ID9834_ABC
body = <some xml>
My goal is to move the only messages looking like Message 2 (and all similar containing an underscore) and not messages without underscores (like Message 1) from the original queue MY_ORDERS.
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">
<cm:property-placeholder persistent-id="com.mycompany.order-temp" update-strategy="reload">
<cm:default-properties>
<cm:property name="amq.url" value="tcp://localhost:61616" />
<cm:property name="queue.to.dump" value="activemq:queue:MY_ORDERS?selector=MyObject+LIKE+'urn:order:%_%'" />
</cm:default-properties>
</cm:property-placeholder>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<onException useOriginalMessage="true">
<exception>java.lang.Exception</exception>
<handled>
<constant>true</constant>
</handled>
<to uri="activemq:queue:MY_ORDERS_DLQ?preserveMessageQos=true" />
</onException>
<route id="route-orders-to-temp">
<from uri="{{queue.to.dump}}" />
<to uri="activemq:queue:MY_ORDERS_TEMP" />
</route>
</camelContext>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="${amq.url}" />
</bean>
</blueprint>
By using the following posts and because the official ActiveMQ Documentation about selectors says it uses SQL 92 syntax:
https://stackoverflow.com/a/17102616/628006
https://stackoverflow.com/a/5822/628006
I tried all the following combinations:
selector=MyObject+LIKE+'urn:sap:order:%_%'
selector=MyObject+LIKE+'urn:sap:order:%_%'
selector=MyObject+LIKE+'urn:sap:order:%\_%'
selector=MyObject+LIKE+'urn:sap:order:%[_]%'
selector=MyObject+LIKE+'urn:sap:order:[a-Z0-9]*_[a-Z0-9]*'
But none of them seems to work. Any thoughts?
Finally I found the solution of my problem: there is a special syntax to define the escaping character which does not seems to be set by default.
By looking on Internet I finally found the following post which clearly shows the underscore must be escaped by e.g. \ then defining the escape character with ESCAPE '\'
If I apply to my cases the following lines:
selector=MyObject+LIKE+'urn:sap:order:%_%' ESCAPE '\'
selector=MyObject+LIKE+'urn:sap:order:%\_%' ESCAPE '\'
will just work fine with the additional ESCAPE '\' at the end of the selector.

Camel Spring DSL Route: set http query parameter

I'm new to camel and in my opinion the documentation is large but could be structured better. So it's hard to find what you are looking for.
My problem: I've defined a camel route in spring DSL for redirection from the camel servlet to another http endpoint. On redirecting, some http query parameter like PARAM1 should be set:
<route id="bridge">
<from uri="servlet:bridge" />
<setHeader headerName="HTTP_QUERY">
<constant>PARAM1=value1</constant>
</setHeader>
<to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>
The redirection works, but the "TO" endpoint doesn't gets the parameter PARAM1.
Where is my mistake?
regards jundl
To send query parameters to an http end point you can use HTTP_QUERY header as below
<route>
<from uri="servlet:bridge" />
<setHeader headerName="HTTP_QUERY">
<constant>param1=value1&param2=value2</constant>
</setHeader>
<to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>
and if you want some dynamic values like a header value as value1 you must use camel simple tag as below
<route>
<from uri="servlet:bridge" />
<setHeader headerName="HTTP_QUERY">
<simple>param1=${headerNameOfValue1}&param2=value2</simple>
</setHeader>
<to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>
Hope it helps!
try this http://camel.apache.org/constant.html
<route>
<from uri="servlet:bridge" />
<setHeader headerName="PARAM1">
<constant>value1</constant>
</setHeader>
<to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>
You are using a wrong headerName. If you want to use in a DSL route the Exchange.HTTP_QUERY constant, you need to write its value. That is, instead of write "HTTP_QUERY", you have to write "CamelHttpQuery". Take a look to https://camel.apache.org/maven/current/camel-core/apidocs/constant-values.html.
If you change your code in this way, it will work:
<route id="bridge">
<from uri="servlet:bridge" />
<setHeader headerName="CamelHttpQuery">
<constant>PARAM1=value1</constant>
</setHeader>
<to uri="http://127.0.0.1:8081/actions.do?bridgeEndpoint=true" />
</route>

Transforming HL7 v2 to XML using apache camel routes

I am new to HL7 .I have to convert the HL7v2 to XML using apache camel routes.I am extracting the HL7 message from file.
Can any one help me how to convert HL7 to XML
There is an HL7 component for unmarshalling the file into a HAPI message. The HAPI api also includes an XMLParser that will convert the message into xml. So you should be able to combine the two into a simple camel route like the following:
<bean id="hl7XmlConverter" class="example.Hl7XmlConverter" />
<bean id="hl7FileFilter"
class="org.apache.camel.component.file.AntPathMatcherGenericFileFilter">
<property name="includes" value="*.hl7" />
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route id="hl7FileRoute">
<from
uri="file:///tmp/test/?delete=true&moveFailed=.error&filter=#hl7FileFilter" />
<convertBodyTo type="java.lang.String" />
<log message="HL7 Request: ${body}" />
<unmarshal>
<hl7 validate="true" />
</unmarshal>
<bean ref="hl7XmlConverter"/>
<log message="HL7 Response: ${body}" />
</route>
</camelContext>
Where the bean is just a simple method:
public String convertMessage(Message message) throws HL7Exception{
XMLParser parser = new DefaultXMLParser();
return parser.encode(message);
}
Depending on your desired xml format, you could also add an xslt after the bean.

Message splitting in Camel

I am trying to write a camel route which would send different elements of a list to different queues.
The message body would be a list with 2 xml's. For example:
<Cat>
<Name>Cat1</Name>
</Cat>,
<Dog>
<Name>Dog1</Name>
</Dog>
Now, I need to send the 'Cat' part of the message i.e. Cat1 part to queue1 and the 'Dog' part of xml i.e. Dog1 to a different queue?
This is the route that I have, but is not working:
<route>
<from uri="jms:queue:InQueue" />
<choice>
<when>
<simple>${in.body} regex 'Cat'</simple>
<to uri="jms:queue:CatQueue" />
</when>
<when>
<simple>${in.body} regex 'Dog'</simple>
<to uri="jms:queue:DogQueue" />
</when>
</choice>
</route>
Any ideas on what am i doing wrong here?
First, you have to split the list using the , token. Second, you have to parse the XML parts using XPath expressions and send the messages to the appropriate JMS queues:
<route>
<from uri="jms:queue:InQueue" />
<split>
<tokenize token=","/>
<log message="Working on split: ${body}" />
<choice>
<when>
<xpath>/Cat</xpath>
<to uri="jms:queue:CatQueue" />
</when>
<when>
<xpath>/Dog</xpath>
<to uri="jms:queue:DogQueue" />
</when>
</choice>
</split>
</route>

Resources