This is the material accompanying the presentation of webinar part II - Transaction Management with Fuse ESB, Camel and Persistent EIPs. It covers the different demo made during the talk and is organized like that :
- aggregator = Camel route project to persist aggregate in H2 DB using JDBCAggregateRepository
- idempotent = Camel route using JPAIdempotentRepository to persist messages already processed
- dao = DAO layer to persist Incident record in H2 DB using OpenJPA
- dao-jta = Idem but configured to use JTA
- features = features to be deployed on Fuse ESB
- route-one-tx-manager = Camel routes using one Global Tx Manager (Aries Tx Manager on Fuse ESB)
- route-two-tx-manager = Camel routes using two separate Tx Managers (JMS and JDBC)
-
Download and install JBoss Fuse: https://access.redhat.com/jbossnetwork/
-
Add the following credentials to the
$JBOSS_FUSE_HOME>etc/users.properties
file:admin=admin,admin
-
Start JBoss Fuse server ./bin/fuse
This example is comprised of the following projects: datasource, dao, route-two-tx-manager. Ensure you have installed the H2 database and the REPORT schema as per the steps above. To install and test, perform the following steps:
-
cd camel-persistence-part2/
-
Run: mvn clean install
-
Install the relevant bundles by executing the following command in the JBoss Fuse console:
features:addurl mvn:com.fusesource.examples.camel-persistence-part2/persistence/1.0/xml/features features:install -r reportincident-jpa-two osgi:refresh
N.B.: You may safely disregard the openjpa.Runtime Warning if it appears.
-
Execute the "list" command in the ESB shell and check that the following bundles are Active:
[...] [Active ] [Created ] [ ] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: Datasource (1.0) [...] [Active ] [ ] [Started] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: DAO (1.0) [...] [Active ] [ ] [Started] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: Camel - 2 Tx Manager (1.0)
-
Start H2 console and connect to the DB using the following parameters Driver class = org.h2.Driver JDBC URL : jdbc:h2:tcp://localhost/~/reportdb User name : sa Password :
Run the following SQL sentence to ensure that the `REPORT.T_INCIDENT` is empty: `SELECT * FROM REPORT.T_INCIDENT`;
-
Launch JConsole (inside $JAVA_HOME/bin) and connect to the local process named "org.apache.karaf.main.Main". Switch to the MBeans tab at the top. On the left pane, expand the org.apache.activemq domain, then navigate to: amq > Queue. You will see the
incident
androllback
queues. TheregisterCall
queue will appear when it is first used. For these queues, you will be interested in tracking the EnqueueCount attribute. service:jmx:rmi://localhost:44444/jndi/rmi://localhost:1099/karaf-root -
Copy the following files and notice the effect in the
registerCall
queue and theREPORT.T_INCIDENT
table:- camel-persistence-part2/data/csv-one-record-allok.txt to $JBOSS_FUSE_HOME/datainsert --> record written in table, new message on registerCall queue - camel-persistence-part2/data/csv-one-record-failjms-dbok.txt to $JBOSS_FUSE_HOME/datainsert --> record written in table, NO new message on registerCall queue - camel-persistence-part2/data/csv-one-record-jmsok-faildb.txt to $JBOSS_FUSE_HOME/datainsert --> NO record written in table, new message on registerCall queue - camel-persistence-part2/data/csv-one-record-failjms-faildb.txt to $JBOSS_FUSE_HOME/datainsert --> NO record written in table, NO new message on registerCall queue
This example is comprised of the following projects: datasource, dao-jta, route-one-tx-manager. (NOTICE bundle names: dao-jta and route-one-tx-manager) Ensure you have installed the H2 database and the REPORT schema as per the steps above.
To install and test, assuming that you have previously run the "Camel Route with 2 Tx Managers" example above:
-
First uninstall the reportincident-jpa-two feature:
features:uninstall reportincident-jpa-two
-
Install the reportincident-jpa-one feature:
features:install -r reportincident-jpa-one osgi:refresh
-
Execute the "list" command in the ESB shell and check that the following bundles are Active:
[...] [Active ] [Created ] [ ] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: Datasource (1.0) [...] [Active ] [ ] [ ] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: DAO - JTA (1.0) [...] [Active ] [ ] [Started] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: Camel - 1 Tx Manager (1.0)
-
Copy the following files and notice the new behaviours in the second and third cases, in terms of the registerCall queue and the REPORT.T_INCIDENT table:
- camel-persistence-part2/data/csv-one-record-allok.txt to $JBOSS_FUSE_HOME/datainsert --> record written in table, new message on registerCall queue - camel-persistence-part2/data/csv-one-record-failjms-dbok.txt to $JBOSS_FUSE_HOME/datainsert --> NO record written in table, NO new message on registerCall queue - camel-persistence-part2/data/csv-one-record-jmsok-faildb.txt to $JBOSS_FUSE_HOME/datainsert --> NO record written in table, NO new message on registerCall queue - camel-persistence-part2/data/csv-one-record-failjms-faildb.txt to $JBOSS_FUSE_HOME/datainsert --> NO record written in table, NO new message on registerCall queue
- Cd idempotent
- Execute mvn camel:run
- Start H2 console and connect to the DB using the following parameters Driver class = org.h2.Driver JDBC URL : jdbc:h2:tcp://localhost/~/idempotentReport User name : sa Password :
- Enter the following request to verify that no records have been inserted SELECT * FROM CAMEL_MESSAGEPROCESSED
- Copy the following file cp ../data/csv-one-record.txt datainsert/
- The exchange is not filtered out and camel logs that %%% File receive -> csv-one-record.txt
- Shutdown the camel route and restart Verify after copying the file that the camel route will not display the following message %%% File receive -> csv-one-record.txt
-
Cd aggregator
-
Start H2 console and connect to the DB using the following parameters Driver class = org.h2.Driver JDBC URL : jdbc:h2:tcp://localhost/~/aggregationReport User name : sa Password :
-
Create the DB using script in directory src/main/resources/sql/init.sql
-
Execute mvn camel:run
-
Shutdown camel when 2-3 exchanges have been aggregated
>>> (file-to-queue) from(timer://demo?period=2000&repeatCount=15) --> ref:users method: getUser <<< Pattern:InOnly, Headers:{firedTime=Wed Nov 23 11:38:51 CET 2011, breadcrumbId=ID-biker-chm-local-53796-1322044729997-0-2}, BodyType:null, Body:[Body is null] >>> (file-to-queue) ref:users method: getUser --> aggregate <<< Pattern:InOnly, Headers:{firedTime=Wed Nov 23 11:38:51 CET 2011, breadcrumbId=ID-biker-chm-local-53796-1322044729997-0-2, id=FUSE}, BodyType:String, Body:Charles, >>> (file-to-queue) from(timer://demo?period=2000&repeatCount=15) --> ref:users method: getUser <<< Pattern:InOnly, Headers:{breadcrumbId=ID-biker-chm-local-53796-1322044729997-0-5, firedTime=Wed Nov 23 11:38:53 CET 2011}, BodyType:null, Body:[Body is null] >>> (file-to-queue) ref:users method: getUser --> aggregate <<< Pattern:InOnly, Headers:{firedTime=Wed Nov 23 11:38:53 CET 2011, id=FUSE, breadcrumbId=ID-biker-chm-local-53796-1322044729997-0-5}, BodyType:String, Body:Raul,
-
Verify that a blob object exist in the DB SELECT * FROM AGGREGATIONREPO1
-
Restart camel route and verify that aggregation process continues