Skip to content

Commit 99437e8

Browse files
committed
Initial upload
0 parents  commit 99437e8

File tree

46 files changed

+3108
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3108
-0
lines changed

README.txt

+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
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+

aggregator/pom.xml

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>com.fusesource.examples</groupId>
8+
<artifactId>camel-persistence-part2</artifactId>
9+
<version>1.0</version>
10+
</parent>
11+
12+
<groupId>com.fusesource.examples.camel-persistence-part2</groupId>
13+
<artifactId>aggregator</artifactId>
14+
<name>FuseSource :: Examples :: Fuse ESB &amp; Persistence :: Camel - Aggregator</name>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>com.fusesource.examples.camel-persistence-part2</groupId>
19+
<artifactId>dao</artifactId>
20+
<version>${project.version}</version>
21+
</dependency>
22+
23+
<dependency>
24+
<groupId>org.springframework</groupId>
25+
<artifactId>org.springframework.jdbc</artifactId>
26+
<version>${spring-version}</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>com.h2database</groupId>
30+
<artifactId>h2</artifactId>
31+
<version>${h2-version}</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>commons-dbcp</groupId>
35+
<artifactId>commons-dbcp</artifactId>
36+
<version>1.4</version>
37+
</dependency>
38+
39+
<dependency>
40+
<groupId>org.apache.openjpa</groupId>
41+
<artifactId>openjpa</artifactId>
42+
<version>2.1.0</version>
43+
<scope>compile</scope>
44+
</dependency>
45+
<dependency>
46+
<groupId>org.apache.camel</groupId>
47+
<artifactId>camel-core</artifactId>
48+
<version>${camel-version}</version>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.apache.camel</groupId>
52+
<artifactId>camel-spring</artifactId>
53+
<version>${camel-version}</version>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.apache.camel</groupId>
57+
<artifactId>camel-sql</artifactId>
58+
<version>${camel-version}</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.apache.camel</groupId>
62+
<artifactId>camel-bindy</artifactId>
63+
<version>${camel-version}</version>
64+
</dependency>
65+
<!-- Logging -->
66+
<dependency>
67+
<groupId>org.slf4j</groupId>
68+
<artifactId>slf4j-log4j12</artifactId>
69+
<version>${slf4j-version}</version>
70+
</dependency>
71+
<dependency>
72+
<groupId>log4j</groupId>
73+
<artifactId>log4j</artifactId>
74+
<version>${log4j-version}</version>
75+
</dependency>
76+
</dependencies>
77+
78+
<build>
79+
<plugins>
80+
<plugin>
81+
<groupId>org.apache.camel</groupId>
82+
<artifactId>camel-maven-plugin</artifactId>
83+
<version>${camel-version}</version>
84+
<configuration>
85+
<applicationContextUri>META-INF/spring/camelRoutes.xml</applicationContextUri>
86+
</configuration>
87+
</plugin>
88+
</plugins>
89+
</build>
90+
91+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.fusesource.examples.persistence.part2.aggregator;
2+
3+
/**
4+
* Copyright 2011 FuseSource
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import org.apache.camel.Exchange;
20+
import org.apache.camel.processor.aggregate.AggregationStrategy;
21+
22+
public class MyAggregationStrategy implements AggregationStrategy {
23+
24+
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
25+
if (oldExchange == null) {
26+
return newExchange;
27+
}
28+
String body1 = oldExchange.getIn().getBody(String.class);
29+
String body2 = newExchange.getIn().getBody(String.class);
30+
31+
oldExchange.getIn().setBody(body1 + body2);
32+
return oldExchange;
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.fusesource.examples.persistence.part2.aggregator;
2+
3+
/**
4+
* Copyright 2011 FuseSource
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import org.apache.camel.Exchange;
20+
21+
import java.io.Serializable;
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
25+
public class Users implements Serializable {
26+
27+
private static List<String> aList = new ArrayList<String>();
28+
private static int count = -1;
29+
30+
static {
31+
aList.add("Charles, ");
32+
aList.add("Raul, ");
33+
aList.add("Emma, ");
34+
aList.add("Corine, ");
35+
aList.add("James, ");
36+
aList.add("Rich, ");
37+
aList.add("Claus, ");
38+
aList.add("Hiram, ");
39+
aList.add("Gert, ");
40+
aList.add("Willem, ");
41+
aList.add("Larry, ");
42+
aList.add("Matt.");
43+
}
44+
45+
public void getUser(Exchange ex) throws Exception {
46+
if (count <= 10) {
47+
count++;
48+
}
49+
50+
if (count == 3) {
51+
// throw new Exception("$$$ The machine has crashed.");
52+
}
53+
54+
ex.getIn().setHeader("id","FUSE");
55+
ex.getIn().setBody(aList.get(count));
56+
57+
}
58+
59+
}

0 commit comments

Comments
 (0)