Time out error in processing route - apache-camel

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

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>

How to setBody in camelcontext route from the xml recieved to pojo class?

<from uri="direct:validating-route" />
<setBody>
<simple>${body}</simple>
</setBody>
<log message="Mapping request from source to destination"
loggingLevel="INFO" />
<to
uri="dozer:transformValidateWrapperType?mappingFile=mappings/validate-mapping.xml&targetModel=in.map.loc.elements.ValidateWrapperType" />
<log message="Completed MApping and sending request"
loggingLevel="INFO" />
<setBody>
<simple>${body}</simple>
</setBody>
<setHeader headerName="operationNamespace">
<constant>http://in.map.com/functions/tele/ap</constant>
</setHeader>
<to uri="cxf:bean:validateOutside" />
The body passed after the set body is null. This is the route for a SOAP request. How to get In the body of the exchange with the needed classes object in the camel route itself?

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>

Is there a way in Apache Camel by which a lock can be obtained and released by a route on another route

I am looking out for a way by which a route can obtain and release a lock on another route, Below is my code snippet and I am looking for a solution where snmp-trap-route and snmp-timer-route can obtain an exclusive lock on business-logic-route and while one is processing other should wait till it completion.
<route id="snmp-trap-route">
<from uri="snmp:{{snmp.host}}:{{snmp.port}}?protocol=udp&type=TRAP" />
<to uri="direct:snmp-main-route"/>
<route id="snmp-timer-route">
<from uri="timer://pulse?fixedRate=true&period=1000" />
<to uri="direct:snmp-main-route"/>
<route id="snmp-main-route">
<from uri="direct:snmp-main-route" />
<choice>
<when>
<simple>${property[batch.ended]} == true </simple>
<to uri="direct:transacted-endpoint" />
</when>
<when>
<simple>${property[batch.started]} == true </simple>
<to uri="direct:business-logic-endpoint" />
</when>
<otherwise>
<to uri="direct:business-logic-endpoint" />
</otherwise>
</choice>
</route>
<route id="business-logic-route">
<from uri="direct:business-logic-endpoint"/>
<setProperty propertyName="route.name">
<constant>TestRoute</constant>
</setProperty>
<process ref="messageMultiplierProcessor" />
<process ref="calculatedFieldsProcessor" />
<process ref="tableProcessor" />
</route>
<route id="transacted-route">
<from uri="direct:transacted-endpoint"/>
<transacted/>
<to uri="direct:business-logic-endpoint"/>
<onException>
<exception>java.lang.Exception</exception>
<handled>
<constant>true</constant>
</handled>
<rollback markRollbackOnly="true"/>
</onException>
</route>
You could reach the same result by using a queue.
A queue processes the messages 1-by-1. You can use the Seda component to achieve this if your route is in the same camelcontext. Otherwise you can use activemq
<route id="snmp-trap-route">
<from uri="snmp:{{snmp.host}}:{{snmp.port}}?protocol=udp&type=TRAP" />
<to uri="seda:business-logic-route"/>
<route id="snmp-timer-route">
<from uri="timer://pulse?fixedRate=true&period=1000" />
<to uri="seda:business-logic-route"/>
<route id="business-logic-route">
<from uri="seda:business-logic-endpoint"/>
<setProperty propertyName="esq.route.name">
<constant>TestRoute</constant>
</setProperty>
<process ref="messageMultiplierProcessor" />
<process ref="calculatedFieldsProcessor" />
This way the next message in the business-logic-route will only be processed after the business-logic-route is finished. Maybe this is what you are looking for.

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" />

Resources