Redhat JBoss Fuse & Apache Camel - How nested routes XML with 3 files? - apache-camel

I am trying to call route in a xml File, with 3 Levels
1) At first it's possible to call nested routes without limitations ?
2) This my example:
My First File call RootFile01.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Configures the Camel Context -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<!-- Import Framework. -->
<import resource="classpath*:META-INF/spring/camel-context-framework*.xml"/>
<import resource="File0A01.xml"/>
<import resource="File0B01.xml"/>
<camelContext id="camelContext-db465ea3-e2da-4931-8902-0c771d2eac3c" xmlns="http://camel.apache.org/schema/spring">
<routeContextRef ref="routeContextNested0A01"/>
<routeContextRef ref="routeContextNested0B01"/>
<route handleFault="true" id="_route1">
<from id="_from1" uri="coveo-soap://test"/>
<recipientList id="_recipientList1">
<method ref="soapDynamicRouter"/>
</recipientList>
</route>
</camelContext>
</beans>
My second File File0A01.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Configures the Camel Context -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<routeContext id="routeContextNested0A01"
xmlns="http://camel.apache.org/schema/spring">
<route handleFault="true" id="routeNested0A01">
<from uri="direct://Nested0A01" />
<log message="=Data In ${body}"></log>
<to uri="direct://routeNested0B01" />
</route>
</routeContext>
</beans>
My third file File0B01.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:camel="http://camel.apache.org/schema/spring"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<routeContext id="routeContextNested0B01"
xmlns="http://camel.apache.org/schema/spring">
<route id="routeNested0B01">
<from uri="direct://routeNested0B01"/>
<log message="Data In - ${body}"></log>
</route>
</routeContext>
</beans>
It's seem, RootFile01.xml can find routeNested0A01 in my second File File0A01.xml. But my second File File0A01.xml cannot reach routeNested0B01 in my third file File0B01.xml.
Error Message:
Exhausted after delivery attempt: 1 caught: org.apache.camel.component.direct.DirectConsumerNotAvailableException: No consumers available on endpoint: Endpoint[direct://routeNested0B01]
How should I resolve this problem?

Related

adding options after query parameters apache camel spring DSL

I am trying to do a get request to the following url:
http://hellostackexchange?mynameiskees.json
the problem is that i don't see how i can add the option parameters after i have added the query parameters to the uri. My attempt is the following:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route id="hello stackexchange">
<from uri="timer://counting_camera?fixedRate=true&period=1000" />
<setHeader headerName="CamelHttpQuery">
<simple>"mynameiskees.json"</simple>
</setHeader>
<to uri=http4://hellostackexchange/>
<to uri = "direct:test"/>
</route>
<route id = "final">
<from uri="direct:test?authUsername=kees&authPassword=kees"/>
<to uri="log:result"/>
</route>
</camelContext>
this results in the error:
There are 2 parameters that couldn't be set on the endpoint. Check the uri
if the parameters are spelt correctly and that they are properties of the
endpoint. Unknown parameters=[{authPassword=kees, authUsername=kees}]
any tips on how to do this?
Withe the help of #Namphibian i did the following, you can just add your query parameters to a header and add the options to your uri:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route id="hello stackexchange">
<from uri="timer://counting_camera?fixedRate=true&period=1000" />
<setHeader headerName="CamelHttpQuery">
<simple>"mynameiskees.json"</simple>
</setHeader>
<to uri="http4://hellostackexchange?authUsername=kees&authPassword=kees"/>
<to uri = "log:result"/>
</route>
</camelContext>

Time out error in processing route

I am sending a request to a rest api from queue, and getting a response back.if the response is not 201 then I have to push the same request to the queue again for a second time. But when I am pushing it to the queue, I am getting an error, like the one below:
org.apache.camel.ExchangeTimedOutException: The OUT message was not received within: 20000 millis due reply message with correlationID: Camel-ID-01HW828056-64538-1479908182896-32-4 not received on destination: temp-queue://ID:01HW828056-64546-1479908191870-15:3:1.
this is my blueprint.xml
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:cxf-core="http://cxf.apache.org/blueprint/core"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<camelContext xmlns="http://camel.apache.org/schema/blueprint" trace="false">
<route id="fromqueuecontext">
<from uri="activemq:queue:request?asyncConsumer=true"/>
<unmarshal>
<jaxb partClass="partclassname" prettyPrint="true" contextPath="contextname"/>
</unmarshal>
<setProperty propertyName="capturequeuebean">
<simple>${body}</simple>
</setProperty>
<log message="${property.capturequeuebean.orderNum}"/>
<log message="${property.capturequeuebean.transactionNumber}"></log>
<removeHeaders pattern="*" />
<setHeader headerName="CamelHttpMethod" id="_setHeader1">
<constant>PUT</constant>
</setHeader>
<setHeader headerName="Content-Type" id="_setHeader2">
<constant>application/json</constant>
</setHeader>
<setBody>
<simple>${body.captureRequest}</simple>
</setBody>
<marshal>
<json library="Jackson"/>
</marshal>
<log message="sending body ${body}"/>
<convertBodyTo type="java.io.InputStream" id="_convertBodyTo1" />
<recipientList>
<simple><!--url to be sent --></simple>
</recipientList>
<log message="${header.CamelHttpResponseCode}" />
<choice>
<when>
<simple>${header.CamelHttpResponseCode} != 201 and ${property.capturequeuebean.count} > 0</simple>
<log message="inside 1st when"></log>
<setBody>
<simple>${property.capturequeuebean}</simple>
</setBody>
<bean ref="CaptureBusinessImpl" method="changecount"></bean>
<log message="${body.count}"></log>
<to uri="activemq:queue:request" />
</when>
<otherwise>
<choice>
<when>
<simple>${header.CamelHttpResponseCode} == 201 </simple>
<log message="Sucess"></log>
</when>
<otherwise>
<choice>
<when>
<simple>${property.capturequeuebean.count} == 0</simple>
<log message="exception"></log>
</when>
</choice>
</otherwise>
</choice>
</otherwise>
</choice>
</route>
</camelContext>
</blueprint>
Somewhere a JMSReplyTo header is being specified and the activemq component is creating a consumer on a temp-queue waiting for a response. The response is not being returned in 20,000 ms, so the activemq component is giving up and throwing the error.
The automatic replyTo handling can be disabled by adding the following options to the activemq endpoint:
?disableReplyTo=true&preserveMessageQos=true
See notes here: Camel JMS Component

Camel : How to set matchOnUriPrefix=true for jetty component configured in <restConfiguration>

I have following camel routing configuration.
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<!-- Rest Configuration -->
<restConfiguration component="jetty" port="9092" bindingMode="auto">
<dataFormatProperty key="json.in.disableFeatures" value="FAIL_ON_UNKNOWN_PROPERTIES" />
</restConfiguration>
<rest path="/" consumes="application/json"
produces="application/json">
<post uri="/" type="com.aaa.xxxx.esb.config.xxxxEsbJsonMapping">
<route>
<setHeader headerName="Authorization">
<simple>Basic YWRtaXXXXWRtaW4=</simple>
</setHeader>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<setHeader headerName="RestEndpointURL">
<simple>
http://${body.serviceURL}?bridgeEndpoint=true
</simple>
</setHeader>
<setBody>
<simple>{"UserDetails": ${body.serviceDataJsonObj}}</simple>
</setBody>
<log message="Exchanged headers : ${headers.RestEndpointURL}" />
<recipientList>
<simple>${headers.RestEndpointURL}</simple>
</recipientList>
</route>
</post>
</rest>
What I need to know is where I can set
matchOnUriPrefix=true
option for the jetty component which I have already configured for camel rest.
According to the Claus Ibsen answer, I changed configuration XML as follows.
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<!-- Rest Configuration -->
<restConfiguration component="jetty" port="9092"
bindingMode="auto">
<dataFormatProperty key="json.in.disableFeatures"
value="FAIL_ON_UNKNOWN_PROPERTIES" />
<componentProperty key="matchOnUriPrefix" value="true" />
</restConfiguration>
<!-- Rest Services -->
<rest path="/" consumes="application/json" produces="application/json">
<post uri="/" type="com.aaa.xxxx.esb.config.xxxxEsbJsonMapping">
<route>
<setHeader headerName="Authorization">
<simple>Basic YWRXXX46YWRtaW4=</simple>
</setHeader>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<setHeader headerName="RestEndpointURL">
<simple>
http://${body.serviceURL}?bridgeEndpoint=true
</simple>
</setHeader>
<setBody>
<simple>{"SystemUserDetails": ${body.serviceDataJsonObj}}</simple>
</setBody>
<log message="Exchanged headers : ${headers.RestEndpointURL}" />
<recipientList>
<simple>${headers.RestEndpointURL}</simple>
</recipientList>
</route>
</post>
</rest>
</camelContext>
I'm using servicemix apache-servicemix-7.0.0.M2
I upgraded its camel ver 2.16.3 to 2.17.3
Thanks
The rest-dsl is configured using the componentProperty in the restConfiguration:
<restConfiguration component="jetty" port="9092" bindingMode="auto">
<componentProperty key="matchOnUriPrefix" value="true"/>
<dataFormatProperty key="json.in.disableFeatures" value="FAIL_ON_UNKNOWN_PROPERTIES" />
</restConfiguration>
You can find details about this in the documentation: http://camel.apache.org/rest-dsl
U may add inside
route
tag as below:
<route>
<from uri="jetty://foo?matchOnUriPrefix=true"/>
...
</route>

How to define ActiveMQ component in format of JMS Component in Apache Camel

I'm using Apache Camel 2.11.1. It seems that both xml definitions are not equivalent in Camel:
First definition:
<bean id="amq" class="org.apache.activemq.camel.component.ActiveMQComponent"
p:brokerURL="tcp://localhost:61616" p:transacted="true"
p:cacheLevelName="CACHE_CONSUMER" p:concurrentConsumers="20"
p:maxConcurrentConsumers="500" p:idleConsumerLimit="10" />
Second definition:
<bean id="amq" class="org.apache.camel.component.jms.JmsComponent"
p:configuration-ref="jmsConfig" p:transacted="true" p:cacheLevelName="CACHE_CONSUMER" />
<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration"
p:connectionFactory-ref="nakedConnectionFactory"
p:concurrentConsumers="20" p:maxConcurrentConsumers="500"
p:idleConsumerLimit="10" />
<bean id="nakedConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
p:brokerURL="tcp://localhost:61616" />
Since the first definition works well on the following route, but the second doesn't.
<route>
<from uri="amq:example.MyQueue" />
<setHeader headerName="myRoutingSlipHeader">
<constant>amq:one#amq:two#amq:three#amq:four</constant>
</setHeader>
<log message="Makan" />
<setExchangePattern pattern="InOut" />
<routingSlip uriDelimiter="#">
<header>myRoutingSlipHeader</header>
</routingSlip>
<setExchangePattern pattern="InOnly" />
<log message="End: ${body}" />
</route>
<route>
<from uri="amq:one" />
<to uri="bean:helloBean?method=stepOne" />
</route>
<route>
<from uri="amq:two" />
<to uri="bean:helloBean?method=stepTwo" />
</route>
<route>
<from uri="amq:three" />
<to uri="bean:helloBean?method=stepThree" />
</route>
<route>
<from uri="amq:four" />
<to uri="bean:helloBean?method=stepFour" />
</route>
The second component definition causes hang during execution.
Seems to work fine for me. I did have to override the spring version with the created archetype. But I used this and it worked fine.
Please find my example project here :
https://github.com/jimternet/camel-activemq
<broker xmlns="http://activemq.apache.org/schema/core" useJmx="true"
persistent="false">
<transportConnectors>
<transportConnector uri="tcp://localhost:61616" />
</transportConnectors>
</broker>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file:src/data?noop=true" />
<to uri="activemq:personnel.records" />
</route>
<route>
<from uri="activemq:personnel.records" />
<log message="${body}" />
<choice>
<when>
<xpath>/person/city = 'London'</xpath>
<to uri="file:target/messages/uk" />
</when>
<otherwise>
<to uri="file:target/messages/others" />
</otherwise>
</choice>
</route>
</camelContext>
<bean id="activemq" class="org.apache.camel.component.jms.JmsComponent"
p:configuration-ref="jmsConfig" p:transacted="true" p:cacheLevelName="CACHE_CONSUMER" />
<bean id="jmsConfig" class="org.apache.camel.component.jms.JmsConfiguration"
p:connectionFactory-ref="nakedConnectionFactory"
p:concurrentConsumers="20" p:maxConcurrentConsumers="500"
p:idleConsumerLimit="10" />
<bean id="nakedConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
p:brokerURL="tcp://localhost:61616" />

Camel- Split List<MyObj> and process each java object - XML Config

I am unable to split Java objects that are in a List. How I can tokenize / convert Body to to single java objects?
<route id="cleanupMigratedFiles" autoStartup="true">
<from uri="timer://kickoff?period=5s" />
<bean ref="migrationProcessor" method="getCacheDeleteObjects" /> <!-- this gives me a List-of-CacheMigr -->
<log message="\n\t########\n\tCleanupMigrated file: ${body}" />
<pipeline>
<split>
<tokenize /> <!-- How to tokenize a List-of-CacheMigr -->
<convertBodyTo type="era.oddw.entity.CacheMigr" /> <!-- Do I need this? -->
<log message="\n\t########\n\tCleanupMigrated file: ${body}" />
</split>
</pipeline>
</route>
Found the answer after some more reading .. The following tag tokenized List properly : ${body}
Thanks to Camel guys.
<split streaming="true">
<simple>${body}</simple>
<convertBodyTo type="era.oddw.entity.CacheMigr" />
<log message="\n\t########\n\tCleanupMigrated file each: ${body}" />
</split>

Resources