|
| 1 | +<!-- |
| 2 | + ~ Copyright 2011 FuseSource |
| 3 | + ~ |
| 4 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + ~ you may not use this file except in compliance with the License. |
| 6 | + ~ You may obtain a copy of the License at |
| 7 | + ~ |
| 8 | + ~ http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + ~ |
| 10 | + ~ Unless required by applicable law or agreed to in writing, software |
| 11 | + ~ distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + ~ See the License for the specific language governing permissions and |
| 14 | + ~ limitations under the License. |
| 15 | + --> |
| 16 | + |
| 17 | +DESCRIPTION |
| 18 | +=========== |
| 19 | + |
| 20 | +This is the material accompanying the presentation of webinar part II - Transaction Management with Fuse ESB, Camel and Persistent EIPs. |
| 21 | +It covers the different demo made during the talk and is organized like that : |
| 22 | + |
| 23 | +aggregator = Camel route project to persist aggregate in H2 DB using JDBCAggregateRepository |
| 24 | +idempotent = Camel route using JPAIdempotentRepository to persist messages already processed |
| 25 | +dao = DAO layer to persist Incident record in H2 DB using OpenJPA |
| 26 | +dao-jta = Idem but configured to use JTA |
| 27 | +features = features to be deployed on Fuse ESB |
| 28 | +route-one-tx-manager = Camel routes using one Global Tx Manager (Aries Tx Manager on Fuse ESB) |
| 29 | +route-two-tx-manager = Camel routes using tewo separate Tx Managers (JMS and JDBC) |
| 30 | + |
| 31 | +H2 DATABASE |
| 32 | +=========== |
| 33 | + |
| 34 | + 1) Open a DOS/UNIX console in the folder persistence/database |
| 35 | + |
| 36 | + 2) Download H2 Database (http://www.h2database.com/html/download.html) and install it |
| 37 | + |
| 38 | + 3) Start H2 Server using the bat or shell script |
| 39 | + |
| 40 | + ./h2.sh & |
| 41 | + |
| 42 | + The H2 server is started and to manage the databases from your web browser, simply click on the following url http://localhost:8082/ |
| 43 | + |
| 44 | + 4) Next create the report database |
| 45 | + |
| 46 | + In the login.jsp screen, select Generic (H2) - Server |
| 47 | + Add as settings name : Generic H2 (Server) - Webinar |
| 48 | + and modify the JDBC ur las such : jdbc:h2:tcp://localhost/~/reportdb |
| 49 | + |
| 50 | + Next click on "connect" and the screen to manage the reportdb appears |
| 51 | + |
| 52 | + 5) Create Schema and Tables using the script located in the file camel-persistence-part2/datasource/src/config/hsqldb/reportdb-scripts.sql |
| 53 | + |
| 54 | + Execute the scripts 1), 2) and 3) defined in this file |
| 55 | + |
| 56 | + Check that the records are well created using the command : SELECT * FROM REPORT.T_INCIDENT; |
| 57 | + |
| 58 | + |
| 59 | +FUSE ESB INSTALLATION |
| 60 | +===================== |
| 61 | + |
| 62 | + 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/ |
| 63 | + 2) Start Fuse ESB server /bin/karaf.sh |
| 64 | + |
| 65 | + |
| 66 | +Camel Route with 2 Tx Managers |
| 67 | +============================== |
| 68 | + |
| 69 | +This example is comprised of the following projects: datasource, dao, route-two-tx-manager. |
| 70 | +Ensure you have installed the H2 database and the REPORT schema as per the steps above. |
| 71 | +To install and test, perform the following steps: |
| 72 | + |
| 73 | + 1) cd camel-persistence-part2/ |
| 74 | + 2) Run: mvn clean install |
| 75 | + |
| 76 | + 3) ServiceMix offers a simple JNDI implementation for OSGi, but for this example we are interested in leveraging the more sophisticated Aries JNDI |
| 77 | + lookup handler. Thus, we need to remove the ServiceMix Naming bundle as it will conflict with the Aries JNDI implementation. Run the following command: |
| 78 | + |
| 79 | + list | grep -i naming | grep -i servicemix |
| 80 | + |
| 81 | + Make note of the bundle id (the number inside the leftmost square brackets). |
| 82 | + |
| 83 | + Run the following command: |
| 84 | + |
| 85 | + uninstall <bundle-id> |
| 86 | + |
| 87 | + Restart Karaf (use Ctrl-D to stop it). |
| 88 | + |
| 89 | + 3) Install the relevant bundles by executing the following command in the FUSE ESB console: |
| 90 | + |
| 91 | + features:addurl mvn:com.fusesource.examples.camel-persistence-part2/persistence/1.0/xml/features |
| 92 | + features:install reportincident-jpa-two |
| 93 | + |
| 94 | + N.B.: You may safely disregard the openjpa.Runtime Warning if it appears. |
| 95 | + |
| 96 | + 4) Execute the "list" command in the ESB shell and check that the following bundles are Active: |
| 97 | + |
| 98 | + [...] [Active ] [Created ] [ ] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: Datasource (1.0) |
| 99 | + [...] [Active ] [ ] [Started] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: DAO (1.0) |
| 100 | + [...] [Active ] [ ] [Started] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: Camel - 2 Tx Manager (1.0) |
| 101 | + |
| 102 | + 5) Start H2 console and connect to the DB using the following parameters |
| 103 | + Driver class = org.h2.Driver |
| 104 | + JDBC URL : jdbc:h2:tcp://localhost/~/reportdb |
| 105 | + User name : sa |
| 106 | + Password : |
| 107 | + |
| 108 | + Run the following SQL sentence to ensure that the REPORT.T_INCIDENT is empty: SELECT * FROM REPORT.T_INCIDENT; |
| 109 | + |
| 110 | + 6) 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. |
| 111 | + On the left pane, expand the org.apache.activemq domain, then navigate to: default > Queue. You will see the incident and rollback queues. |
| 112 | + The registerCall queue will appear when it is first used. For these queues, you will be interested in tracking the EnqueueCount attribute. |
| 113 | + |
| 114 | + 7) Copy the following files and notice the effect in the registerCall queue and the REPORT.T_INCIDENT table: |
| 115 | + |
| 116 | + - camel-persistence-part2/data/csv-one-record-allok.txt to $SERVICEMIX_HOME/datainsert --> record written in table, new message on registerCall queue |
| 117 | + - camel-persistence-part2/data/csv-one-record-failjms-dbok.txt to $SERVICEMIX_HOME/datainsert --> record written in table, NO new message on registerCall queue |
| 118 | + - camel-persistence-part2/data/csv-one-record-jmsok-faildb.txt to $SERVICEMIX_HOME/datainsert --> NO record written in table, new message on registerCall queue |
| 119 | + - 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 |
| 120 | + |
| 121 | + |
| 122 | +Camel route with 1 Global Tx Manager |
| 123 | +==================================== |
| 124 | + |
| 125 | +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) |
| 126 | +Ensure you have installed the H2 database and the REPORT schema as per the steps above. |
| 127 | + |
| 128 | +To install and test, assuming that you have previously run the "Camel Route with 2 Tx Managers" example above: |
| 129 | + |
| 130 | + 1) First uninstall the reportincident-jpa-two feature: |
| 131 | + |
| 132 | + features:uninstall reportincident-jpa-two |
| 133 | + |
| 134 | + 2) Install the reportincident-jpa-one feature: |
| 135 | + |
| 136 | + features:install reportincident-jpa-one |
| 137 | + |
| 138 | + 3) Execute the "list" command in the ESB shell and check that the following bundles are Active: |
| 139 | + |
| 140 | + [...] [Active ] [Created ] [ ] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: Datasource (1.0) |
| 141 | + [...] [Active ] [ ] [ ] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: DAO - JTA (1.0) |
| 142 | + [...] [Active ] [ ] [Started] [ 60] FuseSource :: Examples :: Fuse ESB & Persistence :: Camel - 1 Tx Manager (1.0) |
| 143 | + |
| 144 | + 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: |
| 145 | + |
| 146 | + - camel-persistence-part2/data/csv-one-record-allok.txt to $SERVICEMIX_HOME/datainsert --> record written in table, new message on registerCall queue |
| 147 | + - 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 |
| 148 | + - 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 |
| 149 | + - 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 |
| 150 | + |
| 151 | +Idempotent example |
| 152 | +================== |
| 153 | + |
| 154 | + 1) Cd idempotent |
| 155 | + 2) Execute mvn camel:run |
| 156 | + 3) Start H2 console and connect to the DB using the following parameters |
| 157 | + Driver class = org.h2.Driver |
| 158 | + JDBC URL : jdbc:h2:tcp://localhost/~/idempotentReport |
| 159 | + User name : sa |
| 160 | + Password : |
| 161 | + 4) Enter the following request to verify that no records have been inserted |
| 162 | + SELECT * FROM CAMEL_MESSAGEPROCESSED |
| 163 | + 5) Copy the following file |
| 164 | + cp cp ../data/csv-one-record.txt datainsert/ |
| 165 | + 6) The exchange is not filters out and camel logs that |
| 166 | + %%% File receive -> csv-one-record.txt |
| 167 | + 7) Shutdown the camel route and restart |
| 168 | + Verify after copying the file that the camel route will not display the following message |
| 169 | + %%% File receive -> csv-one-record.txt |
| 170 | + |
| 171 | +Aggregator example |
| 172 | +================== |
| 173 | + |
| 174 | + 1) Cd aggregator |
| 175 | + 2) Start H2 console and connect to the DB using the following parameters |
| 176 | + Driver class = org.h2.Driver |
| 177 | + JDBC URL : jdbc:h2:tcp://localhost/~/aggregationReport |
| 178 | + User name : sa |
| 179 | + Password : |
| 180 | + 3) Create the DB using script in directory sql/init.sql |
| 181 | + 4) Execute mvn camel:run |
| 182 | + 5) Shutdown camel when 2-3 exchanges have been aggregated |
| 183 | + |
| 184 | + >>> (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] |
| 185 | + >>> (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, |
| 186 | + >>> (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] |
| 187 | + >>> (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, |
| 188 | + |
| 189 | + 6) Verify that a blob object exist in the DB |
| 190 | + SELECT * FROM AGGREGATIONREPO1 |
| 191 | + 7) Restart camel route and verify that aggregation process continues |
| 192 | + |
| 193 | + |
| 194 | + |
| 195 | + |
| 196 | + |
0 commit comments