Camel JMS - Unable to set JMSPriority to IBM MQ Message - apache-camel

We are trying to send JMS text message over IBM mq using Apache Camel. We are able set few JMS header properties except the JMSPriority. We tried setting int value and used resultType="java.lang.Integer" but unable to alter priority. Any clue would be more than helpful.
<route id="mqSender">
<from uri="direct:mqSender"></from>
<filter>
<simple> ${body} != null</simple>
<setProperty propertyName="originalRequest">
<simple> ${body}</simple>
</setProperty>
<setHeader headerName="JMSCorrelationID">
<simple>${body.messageContextVO.requestID}</simple>
</setHeader>
<setHeader headerName="VersionId">
<simple>${body.metadata["VersionId"]}</simple>
</setHeader>
<setHeader headerName="FunctionId">
<simple>${body.metadata["FunctionId"]}</simple>
</setHeader>
<setHeader headerName="Format">
<simple>${body.metadata["Format"]}</simple>
</setHeader>
<choice>
<when>
<simple>${property.originalRequest.metadata["FetchPriorityValue"]}== "true"</simple>
<transform>
<simple>${body.formattedData}</simple>
</transform>
<setHeader headerName="JMSPriority">
<simple> ${property.originalRequest.priority}</simple>
</setHeader>
<camel:setHeader headerName="CamelJmsDestinationName"><simple>queue:///${property.originalRequest.metadata["queueName"]}?targetClient=1</simple></camel:setHeader>
</when>
</choice>
<log message="${property.originalRequest.metadata[queueName]}"></log>
<recipientList>
<simple>wmq:queue:${property.originalRequest.metadata["queueName"]}?exchangePattern=InOnly</simple>
</recipientList>
<transform>
<simple>${property.originalRequest}</simple>
</transform>
</filter>
<!-- <to uri="bean:trackerUpdateProcessor?method=process" /> -->
</route>

We found solution to make it work. Priority attribute is required to set at header CamelJmsDestinationName
i.e,
<camel:setHeader headerName="CamelJmsDestinationName"><simple>queue:///${property.originalRequest.metadata["queueName"]}?targetClient=1&priority=${dynamicValue}</simple></camel:setHeader>
Sender code checks for value of priority at MQ Destination level in native code. TimeToLive and Priority values needs to set at MQ destination level to work with Camel.

I am not sure about wmq, but for normal jms component (and I believe camel wmq behave the same) to set JMSPriority for specific message endpoint configuration must have option "preserveMessageQos" set to true
Set to true, if you want to send message using the QoS settings specified on the message, instead of the QoS settings on the JMS endpoint. The following three headers are considered JMSPriority, JMSDeliveryMode, and JMSExpiration. You can provide all or only some of them. If not provided, Camel will fall back to use the values from the endpoint instead. So, when using this option, the headers override the values from the endpoint. The explicitQosEnabled option, by contrast, will only use options set on the endpoint, and not values from the message header.

Related

Set Headers in MULTICAST camel route

<route id="SUB2I0051">
<from uri="seda:SUB2-I0051MTMapper"/>
<multicast>
<to uri="file:C:/complexTest/?fileName=MT_Output.txt" />
<setHeader name="Node">
<simple>File1</simple>
</setHeader>
<to uri="audit:File1?level=info"/>
<to uri="file:C:/complexTest/?fileName=MTY_Output.txt" />
<setHeader name="Node">
<simple>File2</simple>
</setHeader>
<to uri="audit:File1?level=info"/>
</multicast>
</route>
I am trying to set headers inside the multicast tag. Headers need to be sent to an audit bean named as an audit. below is my route. Can anyone help me on this.
The Multicast EIP allows to route the same message to a number of endpoints and process them in a different way. its is important keyword is SAME.default multicast sync okey but camel dont send changed to to next node. u must call set header before multicast eip

Camel blueprint <setHeader headerName="CamelHttpPath" id="_setHeader1"><el>${header.uriPattern}</el></setHeader> waiting for dependencies

I have the following Camel Context.
<camelContext id="_camuatomicservicecontext" xmlns="http://camel.apache.org/schema/blueprint">
<route id="_camuatomicserviceroute1">
<from id="_from1" uri="direct-vm:camuatomicservice">
<description>accepts vm messages directly </description>
</from>
<log id="_log1" message="Camu Atomic Service body = ${body}, header= ${header.uriPattern}"/>
<!-- <to id="_to1" uri="restlet:protocol:localhost:8189/"/> -->
<setHeader headerName="api.key" id="_setHeader1">
<constant>replace later with properties api.key Does not matter for this poc</constant>
</setHeader>
<setHeader headerName="CamelHttpPath" id="_setOutHeader1">
<el>${header.uriPattern}</el>
</setHeader>
<to id="_to1" pattern="InOut" uri="netty4-http:http:localhost:8189/path"/>
<log id="_log2" message="CamuAtomicService Response body ${body}"/>
</route>
</camelContext>
From the documentation I expect the CamelHttpPath header to override the endpoint configuration "/path" such that calling Facade Services can pass the header.uriPattern in and dynamically change the resource they want to access. The bundle worked fine until I added the setHeader for CamelHttpPath and now getting "Waiting for dependencies." I assume I need to install a feature, but Simple EL in other bundles on that server work already so not sure what feature I need to install.
Instead of I used and it worked fine. The choice was farther down in the options.

Apache Camel unzip, process and aggregate not completing

I am trying to process a zip file, which contains several files inside (all small, so working in memory is not a problem) that need to be transformed and zipped together again.
I managed to unzip, transform the files, but for some reason, the splitter is not completing, only using completionTimeout makes the aggregator to create the final zip archive.
Here's the route:
<route id="ZipFile">
<from uri="file:{{file.path.in}}?move=.done&moveFailed=.error&readLock=rename"/>
<setProperty propertyName="OriginalZipName">
<simple>${header.CamelFileName}</simple>
</setProperty>
<unmarshal>
<zipFile usingIterator="true"/>
</unmarshal>
<split streaming="true">
<simple>${body}</simple>
<log message="************ CamelSplitComplete = ${property.CamelSplitComplete}"/>
<to uri="direct:ProcessUnzippedFile"/>
<setHeader headerName="CamelFileName">
<simple>${property.OriginalZipName}</simple>
</setHeader>
<!-- Aggregate to zip -->
<aggregate strategyRef="zipAggregationStrategy" eagerCheckCompletion="true">
<correlationExpression>
<constant>true</constant>
</correlationExpression>
<completionPredicate>
<simple>${property.CamelSplitComplete}</simple>
</completionPredicate>
<setHeader headerName="CamelFileName">
<simple>${property.OriginalZipName}</simple>
</setHeader>
<to uri="file://{{file.path.out}}"/>
</aggregate>
</split>
</route>
Any idea what could be the issue?
The Camel Splitter provides a built- in aggregator, which makes it even easier to
aggregate split messages back into single outgoing message
You have to define the aggregation strategy in the split definition
<split strategyRef="zipAggregationStrategy">
Haven't tried it in XML but in Java DSL this is one of my examples that does exactly that.
.unmarshal(zipFile)
.split(bodyAs(Iterator.class),new ZipAggregationStrategy(true,true))
.streaming()
.stopOnException()
.to("direct:transform-ticket")
.end();

Terminate the current camel exchange

I am processing file in cluster environment. The cluster works fine. It is being processed on Only one server.
But on the second server It identifies as duplicates but still execute the form route delete=true
ERROR:
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot delete file:
I am setting header CamelRouteStop to true but the exchange still try's to delete a file, instead of stop executing the route.
All I need is to end the route if it is duplicate.
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="smb:url?delete=true"/>
<idempotentConsumer messageIdRepositoryRef="myRepo">
<header>messageId</header>
<setHeader headerName="fileExist">
<simple>true</simple>
</setHeader>
</idempotentConsumer>
<when>
<simple>${header.fileExist} == null</simple>
<log message="File ${header.CamelFileName} processing/processed by other Nodes - DUPLICATE" loggingLevel="INFO" />
<setHeader headerName="CamelRouteStop">
<simple <simple resultType="java.lang.Boolean">true</simple>>true</simple>
</setHeader>
</when>
</route>
</camelContext>
For CamelRouteStop you need to use setProperty, not setHeader.

How to extract value from Exchange object in camel esb

I have created a simple cxf web service. following is the body of soap message
<soapenv:Body>
<bean:getRTOEmployeeSalary>
<!--Optional:-->
<bean:arg0>sdf</bean:arg0>
</bean:getRTOEmployeeSalary>
</soapenv:Body>
My requirement is to extract the value of arg0 in my camel context file. i.e. i want to log the value of arg0. Please help me on this
<route routePolicyRef="loggingInInterceptor">
<from uri="cxf:bean:rtoemplyeeService"/>
<setHeader headerName="exchange">
<spel>${exchange}</spel>
</setHeader>
<log message="value of arg0======== "/>
<convertBodyTo type="java.lang.String" id="stringInput"/>
<bean ref="rtoEmpBean" method="getRTOEmployeeSalary" beanType="rtoEmpBean" id="govtRTOEmp"/>
</route>
I need to use the value of arg0 here.
We can use camel provided spring expression language to extract the value from exchange object. Since exchange object also resides in spring container.
below will be code src to extract the value of arg0 in camel context-
<setHeader headerName="arg0">
<spel>#{exchange.in.body.get(0)}</spel>
</setHeader>
This will set the value of arg0 of soap message in a header named arg0.
http://camel.apache.org/spel.html

Resources