Skip to content

phoenix2life/camel-persistence-part2

 
 

Repository files navigation

DESCRIPTION

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 tewo separate Tx Managers (JMS and JDBC)

H2 DATABASE

  1. Open a DOS/UNIX console in the folder persistence/database

  2. Download H2 Database (http://www.h2database.com/html/download.html) and install it

  3. Start H2 Server using the bat or shell script

    ./h2.sh &

    The H2 server is started and to manage the databases from your web browser, simply click on the following url http://localhost:8082/

  4. Next create the report database

    In the login.jsp screen, select Generic (H2) - Server Add as settings name : Generic H2 (Server) - Webinar and modify the JDBC ur las such : jdbc:h2:tcp://localhost/~/reportdb

    Next click on "connect" and the screen to manage the reportdb appears

  5. Create Schema and Tables using the script located in the file camel-persistence-part2/datasource/src/config/hsqldb/reportdb-scripts.sql

    Execute the scripts 1), 2) and 3) defined in this file

    Check that the records are well created using the command : SELECT * FROM REPORT.T_INCIDENT;

FUSE ESB INSTALLATION

  1. Download and install the Fuse ESB server : http://repo.fusesource.com/nexus/content/repositories/releases/org/apache/servicemix/apache-servicemix/4.4.1-fuse-01-06/
  2. Start Fuse ESB server /bin/karaf.sh

Camel Route with 2 Tx Managers

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:

  1. cd camel-persistence-part2/

  2. Run: mvn clean install

  3. ServiceMix offers a simple JNDI implementation for OSGi, but for this example we are interested in leveraging the more sophisticated Aries JNDI lookup handler. Thus, we need to remove the ServiceMix Naming bundle as it will conflict with the Aries JNDI implementation. Run the following command:

    list | grep -i naming | grep -i servicemix
    
    Make note of the bundle id (the number inside the leftmost square brackets).
    
    Run the following command:
    
    uninstall <bundle-id>
    
    Restart Karaf (use Ctrl-D to stop it).
    
  4. Install the relevant bundles by executing the following command in the FUSE ESB console:

     features:addurl mvn:com.fusesource.examples.camel-persistence-part2/persistence/1.0/xml/features
     features:install reportincident-jpa-two
    
     N.B.: You may safely disregard the openjpa.Runtime Warning if it appears.
    
  5. 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)
    
  6. 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;
    
  7. 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: default > Queue. You will see the incident and rollback queues. The registerCall queue will appear when it is first used. For these queues, you will be interested in tracking the EnqueueCount attribute.

  8. Copy the following files and notice the effect in the registerCall queue and the REPORT.T_INCIDENT table:

        - camel-persistence-part2/data/csv-one-record-allok.txt to $SERVICEMIX_HOME/datainsert --> record written in table, new message on registerCall queue
        - camel-persistence-part2/data/csv-one-record-failjms-dbok.txt to $SERVICEMIX_HOME/datainsert --> record written in table, NO new message on registerCall queue
        - camel-persistence-part2/data/csv-one-record-jmsok-faildb.txt to $SERVICEMIX_HOME/datainsert --> NO record written in table, new message on registerCall queue
        - camel-persistence-part2/data/csv-one-record-failjms-faildb.txt to $SERVICEMIX_HOME/datainsert --> NO record written in table, NO new message on registerCall queue
    

Camel route with 1 Global Tx Manager

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:

  1. First uninstall the reportincident-jpa-two feature:

     features:uninstall reportincident-jpa-two
    
  2. Install the reportincident-jpa-one feature:

     features:install reportincident-jpa-one
    
  3. 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)
    
  4. 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 $SERVICEMIX_HOME/datainsert --> record written in table, new message on registerCall queue
      - camel-persistence-part2/data/csv-one-record-failjms-dbok.txt to $SERVICEMIX_HOME/datainsert --> NO record written in table, NO new message on registerCall queue
      - camel-persistence-part2/data/csv-one-record-jmsok-faildb.txt to $SERVICEMIX_HOME/datainsert --> NO record written in table, NO new message on registerCall queue
      - camel-persistence-part2/data/csv-one-record-failjms-faildb.txt to $SERVICEMIX_HOME/datainsert --> NO record written in table, NO new message on registerCall queue
    

Idempotent example

  1. Cd idempotent
  2. Execute mvn camel:run
  3. 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 :
  4. Enter the following request to verify that no records have been inserted SELECT * FROM CAMEL_MESSAGEPROCESSED
  5. Copy the following file cp cp ../data/csv-one-record.txt datainsert/
  6. The exchange is not filters out and camel logs that %%% File receive -> csv-one-record.txt 7.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

Aggregator example

  1. Cd aggregator

  2. 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 :

  3. Create the DB using script in directory sql/init.sql

  4. Execute mvn camel:run

  5. 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,
    
  6. Verify that a blob object exist in the DB SELECT * FROM AGGREGATIONREPO1

  7. Restart camel route and verify that aggregation process continues

About

This is the material accompanying the presentation of webinar part II - Transaction Management with Fuse ESB, Camel and Persistent EIPs.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published