You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by vcheruvu <vi...@macquarie.com> on 2010/01/06 07:53:25 UTC

@Consumed

Hi Camel-Users,

Can anyone give any hints on using @Consumed annotation. I have written a
sample application where

1. Polling JPAConsumer endpoint gets new record
2. Message translation using Bean Integration to invoke the method.

3. Work in progress - I am trying to figure out how to use @Consumed to mark
that the row has been processed so it won't be queried again. Any hints or
guidance on using @Consumed will be greatly appreciated..
++++++ RouteBuilder +++++++
public class testRouter extends SpringRouteBuilder {
@Override
public void configure() throws Exception {
		 // the following will dump the database to files
       
from("jpa:com.test.entity.OldTableEntity?consumeDelete=false&delay=3000&consumeLockEntity=false")
       .to("bean:testTransformerBean?method=checkIfLookupValueExist");
          

}
}

++++++++++++
+++++Entity class ++++

@Entity
@Table(name = "test_table")
public class OldTableEntity {
@Column(name ="displayID")
	private String displayID;
	@Column(name ="userName")
	private String userName;
	@Column(name ="ordType")

...
getter and setters...
}

++++++++++++++
+++++ camel context ++++++++
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">

  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
    <package>com.test</package>
  </camelContext>
<bean id = "testTransformerBean" class
="com.test.transformation.testTransformer"/>

  <bean id="transactionTemplate"
class="org.springframework.transaction.support.TransactionTemplate">
    <property name="transactionManager">
      <bean class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
      </bean>
    </property>
  </bean>

  <bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
  </bean>

  <bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="camel"/>
  </bean>

  
</beans>

+++

Kind regards,
-Vid-
-- 
View this message in context: http://old.nabble.com/%40Consumed-tp27026797p27026797.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: @Consumed

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Check out the source and test code for camel-jpa
https://svn.apache.org/repos/asf/camel/trunk/components/camel-jpa/src/test/

Generally JPA is very often complex and overkill for simple
integration works where you need to work with a few tables.
So consider twice if you really want to impose the complexity and
overhead of using JPA.


On Wed, Jan 6, 2010 at 7:53 AM, vcheruvu <vi...@macquarie.com> wrote:
>
> Hi Camel-Users,
>
> Can anyone give any hints on using @Consumed annotation. I have written a
> sample application where
>
> 1. Polling JPAConsumer endpoint gets new record
> 2. Message translation using Bean Integration to invoke the method.
>
> 3. Work in progress - I am trying to figure out how to use @Consumed to mark
> that the row has been processed so it won't be queried again. Any hints or
> guidance on using @Consumed will be greatly appreciated..
> ++++++ RouteBuilder +++++++
> public class testRouter extends SpringRouteBuilder {
> @Override
> public void configure() throws Exception {
>                 // the following will dump the database to files
>
> from("jpa:com.test.entity.OldTableEntity?consumeDelete=false&delay=3000&consumeLockEntity=false")
>       .to("bean:testTransformerBean?method=checkIfLookupValueExist");
>
>
> }
> }
>
> ++++++++++++
> +++++Entity class ++++
>
> @Entity
> @Table(name = "test_table")
> public class OldTableEntity {
> @Column(name ="displayID")
>        private String displayID;
>        @Column(name ="userName")
>        private String userName;
>        @Column(name ="ordType")
>
> ...
> getter and setters...
> }
>
> ++++++++++++++
> +++++ camel context ++++++++
> <beans xmlns="http://www.springframework.org/schema/beans"
>       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>       xsi:schemaLocation="
>       http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
>       http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd">
>
>  <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
>    <package>com.test</package>
>  </camelContext>
> <bean id = "testTransformerBean" class
> ="com.test.transformation.testTransformer"/>
>
>  <bean id="transactionTemplate"
> class="org.springframework.transaction.support.TransactionTemplate">
>    <property name="transactionManager">
>      <bean class="org.springframework.orm.jpa.JpaTransactionManager">
>        <property name="entityManagerFactory" ref="entityManagerFactory"/>
>      </bean>
>    </property>
>  </bean>
>
>  <bean id="jpaTemplate" class="org.springframework.orm.jpa.JpaTemplate">
>    <property name="entityManagerFactory" ref="entityManagerFactory"/>
>  </bean>
>
>  <bean id="entityManagerFactory"
> class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
>    <property name="persistenceUnitName" value="camel"/>
>  </bean>
>
>
> </beans>
>
> +++
>
> Kind regards,
> -Vid-
> --
> View this message in context: http://old.nabble.com/%40Consumed-tp27026797p27026797.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: @Consumed

Posted by vcheruvu <vi...@macquarie.com>.
I have figured it out how to use @Consumed after reading the JpaConsumer
class in the camel source.


1) I have added processed field in the table with default 0, which will be
used to check if the record is processed or not.

2) added update method in the OldTableEntity and added @Consumed annotation.
See below

@Consumed
	public void updateProcessedFlag(){
		this.processed = 1;
	}

3) made a change  in routebuilder class as shown below
from("jpa:com.test.entity.OldTableEntity?consumer.query=select x from
OldTableEntity x where
x.processed=0&consumeDelete=false&delay=3000&consumeLockEntity=false") 

That is the only change I had to make to make use of @Consumed annotation to
update the flag.


-- 
View this message in context: http://old.nabble.com/%40Consumed-tp27026797p27038384.html
Sent from the Camel - Users mailing list archive at Nabble.com.