camel - quartz2 endpoint - Multiple consumers for the same endpoint - apache-camel

I am using apache camel and wants to have multiple routes.The route is as below.
endpoint -> quartz2://tsTimer?cron=0%2F20+*+8-18+%3F+*+MON%2CTUE%2CWED%2CTHU%2CFRI+*&stateful=true&trigger.timeZone=Asia%2FSingapore
Call bean method to get data.
Send to MQ
In this case my route is going to be same as the polling interval is same.
The data from bean method will be different.
And the MQ queue will be same.
Failed to start route route2 because of Multiple consumers for the same endpoint is not allowed: quartz2://tsTimer?cron=0%2F20+*+8-18+%3F+*+MON%2CTUE%2CWED%2CTHU%2CFRI+*&stateful=true&trigger.timeZone=Asia%2FSingapore
How do i achieve this? How do i differentiate camel route in case when the endpoint is quartz2 timer?

I din't notice that in endpoint uri I was having tsTimer which will distinguishes other end-points.
Something like below
quartz2://tsTimer1
quartz2://tsTimer2
quartz2://tsTimer3

Related

No endpoint could be found for - Camel Http Integration

I'm trying to run a simple test with Apache Camel:
from("http://localhost:61554/api/v1/MyController/my-endpoint")
.to("direct:a")
.log("$({body}");
I'm getting the following error: "No endpoint could be found for: http://localhost:61554/api/v1/MyController/my-endpoint, please check your classpath contains the needed Camel component jar"
I'm very new to Camel and Java. Can someone please tell me why this error is coming up? Should I be using from("direct:x")... ? If, so where do I map my "direct" endpoints to concrete ones?
Thanks
You cannot use the http component as consumer (eg in from) - its a http client for calling HTTP servers (so its a producer, eg to).
Instead to have HTTP as consumer you can use camel-servlet, camel-jetty, camel-undertow, etc.

Difference between #JMSListener and #Consume annotations?

I am trying to consume JMS messages sent via spring JmsTemplate using #Consume annotated bean. The consumer is not receiving messages when sent using JmsTemplate.
Whereas, when sent using ProducerTemplate of Camel the messages are received.
What is the difference between #org.springframework.jms.annotation.JmsListener and #org.apache.camel.Consume?
Producer Logic
jmsTemplate.convertAndSend("jms:mailbox", message);
Consumer Logic
#Consume(uri="jms:mailbox")
public void onRequest(String name) {
System.out.println("Received message > "+name);
}
Apache Camel #Consume annotation can consume from any endpoint, which supports consuming. This annotation takes uri as parameter. URI consists of scheme, path and optional params. In case of JMS component the scheme is jms, path is Destination (in your case mailbox) and params are additional options customizing behavior of Consumer.
Spring #JmsListener can consume from JMS and takes Destination as parameter.
Your code does not work because the Destination is mailbox, not jms:mailbox. Spring JmsTemplate does not know about jms scheme, it is Camel specific. So use jmsTemplate.convertAndSend("mailbox", message) on Spring side and #Consume(uri="jms:mailbox") on Camel side.

Apache camel Restlet producer cached

I am using camel 2.18.0 version.I am facing a issue while using restlet component in SEDA flow. Please find the route details below
from("timer://foo?repeatCount=1")
.to("http4://localhost:8080/pages")
.split(body())
.to("seda:pageConsumer");
from("seda:pageConsumer?concurrentConsumer=5")
.toD("restlet:${in.body}")
.process(enrich());
Details on route:
"http4://localhost:8080/pages" this rest endpoint returns list of url
url= http://localhost:8080/data?page=1&size=5
seda consumer is used for consuming each page parallel
url "http://localhost:8080/data?page=1&size=5" streams the data (This is a rest endpoint and endpont does not send a list of data instead endpoint streams the data)
restlet endpoint invokes the page url and streams the data.
Issue:
when seda endpoint receives 1st URL all is good i.e. "http://localhost:8080/data?page=1&size=5" rest endpoint is invoked by restlet and expected data is processed in route.
when seda endpoint receives 2nd URL i.e.
"http://localhost:8080/data?page=2&size=5" , this where issue starts instead of invoking rest endpoint with "page=2&size=5" as query param, restlet use query param from 1st URL i.e. "page=1&size=5". and issue continues for rest of the urls.
upon debugging i found out that camel caches producer in ProducerCache
and producer is cached in a hashmap with endpoint uri as the key.
questions why does camel does not honour query param during caching? is there why to avoid the caching?
Please note i got the code working by changing the url to include page details which is ugly. Currently url looks like
http://localhost:8080/data/page/2/size/5.
If the restlet endpoint is calling the same http url (eg host:port) then it can be slightly better to use a plain to with this host:port as static, and then set a header with the dynamic part.
.setHeader(Exchange.HTTP_QUERY, constant("page1=&size=5"))
.to("http:xxxx")
Then the same endpoint/producer is reused and the header then includes the dynamic part with the query parameters.
There is also a header where you can set the context-path as well on Exchange.
If you keep using toD then you can adjust the size of the cache with the cacheSize option - its the same as on recipient list: http://camel.apache.org/recipient-list.html

Apache camel graceful route shutdown

I have a Camel route which Consumes messages from a Queue and stores the message into a Database. Now I wanted to shut down running camel route manually in a graceful manner. I have a RestEndpoint to be triggered whenever I need to stop Camel route. This endpoint should stop the route. But if there is any in-flight message or transaction running during the shutdown it has to be completed successfully without consuming any new messages from from("") endpoint of camel route and shut down after completing inflight message or transaction. Can anyone help me how Can I code this?
Below are the few options to control/monitor camel routes
CamelContext API's
Control bus component
JMX API's
You can go through below two sites to get started
http://camel.apache.org/controlbus.html
https://dzone.com/articles/apache-camel-monitoring
shutdownRunningTask(ShutdownRunningTask.CompleteCurrentTaskOnly)

Camel CXFRS response

camel-fuse 2.8
I have a camel jaxrs server which accepts requests then kicks-off 2 Camel routes.
The first route, consumes requests from cxfrs endpoint/bean and ships them to jms queue inbox.
The second route, consumes requests from jms queue inbox for business logic processing, then ships the results to jms queue outbox.
My question is related to http response and sending the results to jaxrs server consumer.
Is it possible to send an http response back to http client from first route with results from second route? (synchronously)
from("cxfrs:bean:personLookupEndpoint") <-- http client waits for response...
.setExchangePattern(ExchangePattern.InOut)
.process(new RequestProcessor())
.to(inbox);
from(inbox)
.unmarshal(jaxb)
.process(new QueryServiceProcessor())
.to("bean:lookupService?method=processQuery(${body})")
.convertBodyTo(String.class)
.to(outbox); <-- need to send results to font-end consumer synchronously ...
Do you really need to do it using queues? I think that it would be better to use direct: routes instead.
There is a possibility to use the InOut exchange pattern for a JMS endpoint, but it has some limitations: http://fusesource.com/docs/router/2.2/transactions/JMS-Synchronous.html

Resources