Set Headers in MULTICAST camel route - apache-camel

<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

Related

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.

apache camel hazelcast getting custom header

I am trying to get the header or property which i set before calling hazelcast but i couldn't able to get the custom header which i set.
<route>
<from uri=""/>
<setHeader headerName="CamelHazelcastObjectId">
<constant>123</constant>
</setHeader>
<setHeader headerName="CamelHazelcastOperationType">
<constant>put</constant>
</setHeader>
<setHeader headerName="test">
<constant>test</constant>
</setHeader>
<setProperty propertyName="test">
<constant>test</constant>
</setProperty>
<to uri="hazelcast:map:testMap"/>
</route>
When i trying to retrieve my custom header or property couldn't able to get that
<route>
<from uri="hazelcast:map:testMap"/>
<log message = "printing:::: ${in.header.test} and ${property[test]}"/>
<to uri=""/>
Please help on this.
The camel-hazelcast component is only for storing the message body, not message headers.

Camel mail 2.13.0 searchterm: How to configure multiple from addresses?

I only have to consume mails from the mailbox which are from address x OR address y. How can i configure this in a camel uri?
I've only found the searchTerm configuration with 1 address(searchTerm.from=x)
Segment your route using Direct Component, it works like method call.
For example:
<route>
<from uri="imap://admin#mymailserver_1"/>
<to uri="direct:processMail"/>
</route>
<route>
<from uri="imap://admin#mymailserver_2"/>
<to uri="direct:processMail"/>
</route>
<route>
<from uri="direct:processMail"/>
<to uri="bean:MailService?method=process"/>
<to uri="activemq:queue:mail.out"/>
</route>

Camel JMS - Unable to set JMSPriority to IBM MQ Message

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.

How to set endpoint specific header value in Camel Multicast

I want to set the endpoint specific header value in Multicast component.
XML DSL as below:
<route>
<from uri="direct:testRoute"/>
<multicast strategyRef="MyAggregator" parallelProcessing="true">
<to uri="direct:call1"/> <!-- set the header MY_HEADER = "call_1" -->
<to uri="direct:call2/> <!-- set the header MY_HEADER = "call_2" -->
</multicast>
</route>
Basically in the response aggregation I want to know, to which service request this response belongs to.
I tried by doing this, but its not the correct way (parse exception):
<to uri="direct:call1">
<setHeader headerName="MY_HEADER"><simple>call1</simple></setHeader>
</to>
What I see from reading the documentation is that, multicast will copy the source Exchange and multicast each copy. So its a shallow copy of the Exchange and kind of reference shared between all the multicast recipient.
But here I am looking for specific header value for individual recipient.
How to do this? Any pointers?
You can't do that in the multicast route. But it should be simple in the direct route afterwards.
<route>
<from uri="direct:call1"/>
<setHeader headerName="MY_HEADER"><simple>call1</simple></setHeader>
.. do whatever
</from>
</route>
otherwise, if call1 is used for other things and you cannot know when to put the header once in that route, make a simple prep-route:
<route>
<from uri="direct:prepCall1"/>
<setHeader headerName="MY_HEADER"><simple>call1</simple></setHeader>
<to uri="direct:call1"/>
</from>
</route>
As a third option, even though you cannot place DSL (xml or java) in the multicast list, you can supply an "onPrepareRef" processor bean that adds the headers to your exchange. But one processor will handle all multicast endpoints.
There is a header with the key Exchange.TO_ENDPOINT that you can see which of the 2 endpoints the response is from.

Resources