How to implement Aggregation in Camel Seda - apache-camel

Is it possible to aggregate thread processing data from a Seda queue in camel?
Can anyone suggest how it can be done?

You can setup the camel route like this, and you can find more example here
from("seda:header").setHeader("visited", constant(true)).aggregate(header("cheese")).to("mock:result");

Related

ActiveMQ / Camel : spawn multiple routes, wait for all to be completed

I'm new to activeMQ / Camel, so please bear with me.
In a camel route, I use a splitter to spawn multiple sub routes. Each one of this routes will use some external APIs to do some job, and poll until job is done. I'm that far.
Now I need to trigger a last action to collect the result of all of these routes. How would I do that the Camel / AMQ way ?
I was thinking of posting a message in each sub-route to an AMQ queue, but I haven't found a way yet to wait for the N messages to be received in that queue before consuming it in my final Camel route.
Thank you.
If you need to collect all the results from the splitter sub-routes and execute some action on those results after all the sub-routes are completed then you can use an aggregation strategy(https://camel.apache.org/manual/latest/aggregate-eip.html) on the splitter.
By using an aggregation strategy, the Exchange after the split will contain the results of all the sub-routes.
Example using the Java DSL:
.split(expression, new GroupedExchangeAggregationStrategy())
...
.end()
The GroupedExchangeAggregationStrategy aggregates all split Exchanges into a list. You can use another predefined aggregation strategy if you need, or you can create a custom one by extending org.apache.camel.processor.aggregate.AggregationStrategy.

Camel timer to read from a queue

How to write a camel route
with timer..which will read from a jms queue
I have tried like this but not working
example
from(timer:mytimer)
.from("jms:queue)
Please let me know if there is any way

Using Apache Camel ProducerTemplate to send JSON message to ActiveMQ

I have a camel route setup like the following to send a java object to an activemq queue.
from("direct:clientRequest")
.marshal().json(JsonLibrary.Jackson)
.to("activemq:queue:command");
I want to do the following:
Map the "clientRequest" uri to some Java method
Use ProducerTemplate's "sendBody" method to send a JSON form of a Java object to the activemq queue.
Is this possible?
I am asking this question after a lot of homework. Please suggest a way to do this.
You can use pojo producing in Apache Camel. See this page for more details
http://camel.apache.org/pojo-producing.html
And there is an example that shows more about using pojo producing/consuming in Camel
http://camel.apache.org/pojo-messaging-example.html

Force Camel JMS/AMQP component to use separate sessions for producer and consumer

Some AMQP enabled brokers like Microsoft Service Bus or ActiveMQ allow only one active producer or consumer per session. The Apache JMS Camel component seems not be able to handle this correctly, which result that JMS throws exceptions when processing InOut messages sent from e.g. Service Bus.
A small JMS test application with separate sessions for producer and consumer works nice. With using the same session, it run into the same problem.
Issue is rooted in the Spring JMS template, which is used as base for the Camel JMS implementation.
Does anybody know how to overcome that behavior?
You can define a 2nd JMS component and use that for the "other".
Or you can turn off any kind of connection pooling maybe.
If you use XML then you can define a 2nd jms component
<bean id="jms2" class="org.apache.camel.component.jms.JmsComponent"/>

Set TTL Apache Camel JAva DSL

How do you set the TTL for a message when using Java DSL?
I have something like this:
...
from ("timer:something?delay=3000&period=15000")
...
.to("{{some.property}}")
.end()
...
I want to set a time to live on the message being sent.
I ended up setting the JMSExpiration header field of the messages being created similar to the following
.setHeader("JMSExpiration", constant(System.currentTimeMillis() + 1000))
We are using Apache ActiveMQ 5.7.
I assume TTL means Time to Live.
In Camel this is component specific how they deal with this. Some components support this, and others do not.
You should check the documentation for the component you use, what it supports.
If you use JMS component then it has the timeToLive option as documented: http://camel.apache.org/jms
And mind about the problem with "client and server clock's can be out of sync". There is some details on the Camel JMS page. Some message brokers has ways to sync the clocks, such as Apache ActiveMQ with its timestamp plugin: http://activemq.apache.org/timestampplugin.html

Resources