Forum Home » Fuse Distributions » Fuse Mediation Router

Thread: JPA consumer doing constant polling

 
This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Apr 12, 2012 1:46 AM Last Post By: mohithanda Threads: [ Previous | Next ]
mohithanda

Posts: 13
Registered: 11/28/11
JPA consumer doing constant polling
Posted: Dec 15, 2011 11:38 PM
 
  Click to reply to this thread Reply

Hi Guys,


I am trying to write a route which is triggered by a JMS message on a queue. It then polls the database using JPA endpoint, converts the row to an entity. Then I want to do some processing on that entity and finally persist it back to the db.

Following is my route

from("localjms:queue:Test.Queue")

.from("jpa:com.mycompany.servicebus.services.entities.test.TestEntity?consumer.query=select t from com.mycompany.servicebus.services.entities.test.TestEntity t where t.id = 1&consumeDelete=false")

.process(new Processor() {

@Override

public void process(Exchange exchng) throws Exception {

TestEntity entity = exchng.getIn().getBody(TestEntity.class);

if(entity != null){

entity.doSomeStuff();

}

}

})

.to("jpa:com.mycompany.servicebus.services.entities.test.TestEntity")

.end();

Now the issue that I am facing is that the route constantly polls the db, reads the row and does the aforementioned processing. But I want it to be once off. i.e. when a message is sent to the inbound JMS queue. Can you think of a way by which I could achieve this?

I could inject the entity manager and use plain java code. But I would prefer to use DSL.

Any suggestions? Please advise.

Regards,
Mohit

davsclaus

Posts: 1,893
Registered: 10/14/08
Re: JPA consumer doing constant polling
Posted: Dec 16, 2011 5:12 AM   in response to: mohithanda in response to: mohithanda
 
  Click to reply to this thread Reply
You can stop the route using API on CamelContext.

You can also use a RoutePolicy and attach to the route, and control logic to start/stop the route. We have out of the box policy that uses a timer/quartz cron scheduler, so you can define "opening hours" etc.
http://camel.apache.org/routepolicy

And there is also this FAQ to stop a route from a route
http://camel.apache.org/how-can-i-stop-a-route-from-a-route.html

Also there is a delay option on the JPA endpoint, where you can specify polling frequency. eg delay=1h, to poll once per hour.
mohithanda

Posts: 13
Registered: 11/28/11
Re: JPA consumer doing constant polling
Posted: Apr 12, 2012 1:46 AM   in response to: mohithanda in response to: mohithanda
 
  Click to reply to this thread Reply
Ok. Thanks Claus!