2 Replies Latest reply on Apr 11, 2012 9:46 PM by mohithanda

    JPA consumer doing constant polling

    mohithanda

       

      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