Skip to content

Commit 4eba124

Browse files
committed
Refresh jdbc-spring and create jdbc-blueprint examples
1 parent 51d4415 commit 4eba124

File tree

36 files changed

+1370
-342
lines changed

36 files changed

+1370
-342
lines changed

README.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Description
2+
3+
This is the material accompanying the presentation of part I - Database persistence with Camel from simple to more elaborated.
4+
It covers the different demos made during the talk and is organised like that:
5+
6+
* `database`: directory containing the scripts to create the database for H2, HSQLDB and PostgreSQL RDBMSes
7+
* `jdbc-spring`: Maven project using camel-jdbc component and Spring XML DSL
8+
* `jdbc-blueprint`: Maven project using camel-jdbc component and Blueprint XML DSL
9+
10+
# Initial setup
11+
12+
We will refer to the root directory of `camel-persistence-part1` project as `$PROJECT_HOME`.
13+
14+
## Setting up docker-based databases
15+
16+
To perform tests in more realistic environments, we can leverage the power of docker to run more advanced database servers.
17+
Of course you can use existing database instances. The below examples are just here for completeness.
18+
19+
### PostgreSQL database
20+
21+
We can use *official* PostgreSQL docker image available at [docker hub](https://registry.hub.docker.com/_/postgres/).
22+
You can use any of available methods to access PostgreSQL server (e.g., by mapping ports or connecting to containers IP address directly).
23+
24+
1. Start PostgreSQL server docker container:
25+
26+
$ docker run -d --name fuse-postgresql-server -e POSTGRES_USER=fuse -e POSTGRES_PASSWORD=fuse -p 5432:5432 postgres:9.6.4
27+
28+
2. Create `reportdb` database by from the `fuse-postgresql-server` container:
29+
30+
$ docker exec -ti fuse-postgresql-server /bin/bash
31+
root@3e37b4b579c7:/# psql -U fuse -d fuse
32+
psql (9.4.0)
33+
Type "help" for help.
34+
fuse=# create database reportdb owner fuse encoding 'utf8';
35+
CREATE DATABASE
36+
fuse=# \q
37+
38+
3. Initialize database `reportdb` by creating schema, table and populating the table with data.
39+
40+
$ cd $PROJECT_HOME/database
41+
$ docker cp src/config/postgresql/reportdb-postgresql-script.sql fuse-postgresql-server:/tmp
42+
$ docker exec -ti fuse-postgresql-server /bin/bash
43+
$ root@58b0d9de9c5b:/# psql -U fuse -d reportdb -f /tmp/reportdb-postgresql-script.sql
44+
...
45+
DROP SCHEMA
46+
CREATE SCHEMA
47+
CREATE TABLE
48+
INSERT 0 1
49+
INSERT 0 1
50+
INSERT 0 1
51+
INSERT 0 1
52+
53+
# Running examples
54+
55+
## `jdbc-spring` and `jdbc-blueprint`
56+
57+
These examples can be run using camel-test-spring and camel-test-blueprint respectively. Examples will run outside
58+
of Fuse server and require only running database server.
59+
60+
For `jdbc-spring` example, run:
61+
62+
$ cd $PROJECT_HOME/jdbc-spring
63+
$ mvn clean compile camel:run
64+
65+
We will see Camel context being started and after initial delay of 4 secods, every 20 seconds we'll see list of
66+
incidents being printed in console.
67+
68+
Additionally we can trigger `key-from-file` route simply by dropping comma-separated list of incident references
69+
to a file inside `$PROJECT_HOME/jdbc-spring/target/data` directory. Here's example:
70+
71+
$ cd $PROJECT_HOME/jdbc-spring
72+
$ echo -n 002,004 > target/data/keys
73+
74+
We can also run 2nd Camel context using:
75+
76+
$ cd $PROJECT_HOME/jdbc-spring
77+
$ mvn clean compile camel:run -Pcontext2
78+
79+
For `jdbc-blueprint` we use Blueprint XML DSL and because of more _discovery_ nature of `camel-test-blueprint`, we
80+
use only `camelContext1.xml` example. We can run this example using:
81+
82+
$ cd $PROJECT_HOME/jdbc-spring
83+
$ mvn clean package camel:run
84+
85+
The invocation is slightly different - `package` goal has to be invoked, so we have proper OSGi bundle - or rather
86+
proper OSGi bundle `MANIFEST.MF` file generated in `target/classes/META-INF` directory. This allows `camel-test-blueprint`
87+
to _pick up_ `target/classes` directory as correct OSGi bundle.

database/db/idempotentdb.properties

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
#
2+
# Copyright 2005-2017 Red Hat, Inc.
3+
#
4+
# Red Hat licenses this file to you under the Apache License, version
5+
# 2.0 (the "License"); you may not use this file except in compliance
6+
# with the License. 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
13+
# implied. See the License for the specific language governing
14+
# permissions and limitations under the License.
15+
#
16+
117
#HSQL Database Engine 1.8.0.10
218
#Wed Apr 13 15:03:18 CEST 2011
319
hsqldb.script_format=0

database/db/reportdb.properties

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
#
2+
# Copyright 2005-2017 Red Hat, Inc.
3+
#
4+
# Red Hat licenses this file to you under the Apache License, version
5+
# 2.0 (the "License"); you may not use this file except in compliance
6+
# with the License. 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
13+
# implied. See the License for the specific language governing
14+
# permissions and limitations under the License.
15+
#
16+
117
#HSQL Database Engine 1.8.0.10
218
#Wed Apr 13 15:03:18 CEST 2011
319
hsqldb.script_format=0

database/server.properties

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
#
2+
# Copyright 2005-2017 Red Hat, Inc.
3+
#
4+
# Red Hat licenses this file to you under the Apache License, version
5+
# 2.0 (the "License"); you may not use this file except in compliance
6+
# with the License. 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
13+
# implied. See the License for the specific language governing
14+
# permissions and limitations under the License.
15+
#
16+
117
server.database.0=file:db/reportdb
218
server.dbname.0=reportdb
319
server.database.1=file:db/idempotentdb

database/src/config/hsqldb/reportdb-hsqldb-script.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
~ limitations under the License.
1515
-->
1616

17+
1) CREATE REPORT SCHEMA
1718
1) CREATE REPORT SCHEMA
1819
************************
1920

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--
2+
-- Copyright 2005-2017 Red Hat, Inc.
3+
--
4+
-- Red Hat licenses this file to you under the Apache License, version
5+
-- 2.0 (the "License"); you may not use this file except in compliance
6+
-- with the License. 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
13+
-- implied. See the License for the specific language governing
14+
-- permissions and limitations under the License.
15+
--
16+
17+
drop schema if exists report cascade;
18+
19+
create schema report;
20+
21+
create table report.t_incident (
22+
incident_id serial not null primary key,
23+
incident_ref varchar(55),
24+
incident_date timestamp,
25+
given_name varchar(35),
26+
family_name varchar(35),
27+
summary varchar(35),
28+
details varchar(255),
29+
email varchar(60),
30+
phone varchar(35),
31+
creation_date timestamp,
32+
creation_user varchar(255)
33+
);
34+
35+
insert into report.t_incident (incident_ref, incident_date, given_name, family_name, summary, details, email, phone)
36+
values ('001', '2017-01-23 00:00:00', 'Charles', 'Moulliard', 'incident webinar-001', 'This is a report incident for webinar-001', '[email protected]', '+111 10 20 300');
37+
insert into report.t_incident (incident_ref, incident_date, given_name, family_name, summary, details, email, phone)
38+
values ('002', '2017-01-24 00:00:00', 'Charles', 'Moulliard', 'incident webinar-002', 'This is a report incident for webinar-002', '[email protected]', '+111 10 20 300');
39+
insert into report.t_incident (incident_ref, incident_date, given_name, family_name, summary, details, email, phone)
40+
values ('003', '2017-01-25 00:00:00', 'Charles', 'Moulliard', 'incident webinar-003', 'This is a report incident for webinar-003', '[email protected]', '+111 10 20 300');
41+
insert into report.t_incident (incident_ref, incident_date, given_name, family_name, summary, details, email, phone)
42+
values ('004', '2017-01-26 00:00:00', 'Charles', 'Moulliard', 'incident webinar-004', 'This is a report incident for webinar-004', '[email protected]', '+111 10 20 300');

jdbc-blueprint/pom.xml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2005-2017 Red Hat, Inc.
5+
6+
Red Hat licenses this file to you under the Apache License, version
7+
2.0 (the "License"); you may not use this file except in compliance
8+
with the License. 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
15+
implied. See the License for the specific language governing
16+
permissions and limitations under the License.
17+
18+
-->
19+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
22+
<modelVersion>4.0.0</modelVersion>
23+
24+
<parent>
25+
<groupId>com.fusesource.examples</groupId>
26+
<artifactId>camel-persistence-part1</artifactId>
27+
<version>1.0</version>
28+
<relativePath>../pom.xml</relativePath>
29+
</parent>
30+
31+
<groupId>com.fusesource.examples.camel-persistence-part1</groupId>
32+
<artifactId>jdbc-blueprint</artifactId>
33+
<packaging>bundle</packaging>
34+
<name>FuseSource :: Examples :: Camel Persistence :: JDBC Blueprint</name>
35+
36+
<dependencies>
37+
38+
<!-- Camel -->
39+
40+
<dependency>
41+
<groupId>org.apache.camel</groupId>
42+
<artifactId>camel-blueprint</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.apache.camel</groupId>
46+
<artifactId>camel-test-blueprint</artifactId>
47+
<scope>test</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.apache.camel</groupId>
51+
<artifactId>camel-jdbc</artifactId>
52+
</dependency>
53+
54+
<!-- OSGi -->
55+
56+
<dependency>
57+
<groupId>org.osgi</groupId>
58+
<artifactId>osgi.enterprise</artifactId>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.osgi</groupId>
62+
<artifactId>osgi.core</artifactId>
63+
</dependency>
64+
65+
<!-- Spring -->
66+
67+
<dependency>
68+
<groupId>org.springframework</groupId>
69+
<artifactId>spring-jdbc</artifactId>
70+
</dependency>
71+
72+
<!-- Database drivers -->
73+
74+
<dependency>
75+
<groupId>org.postgresql</groupId>
76+
<artifactId>postgresql</artifactId>
77+
</dependency>
78+
79+
</dependencies>
80+
81+
<build>
82+
<plugins>
83+
<plugin>
84+
<groupId>org.apache.felix</groupId>
85+
<artifactId>maven-bundle-plugin</artifactId>
86+
<extensions>true</extensions>
87+
<configuration>
88+
<instructions>
89+
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
90+
</instructions>
91+
</configuration>
92+
</plugin>
93+
<plugin>
94+
<groupId>org.apache.camel</groupId>
95+
<artifactId>camel-maven-plugin</artifactId>
96+
<configuration>
97+
<useBlueprint>true</useBlueprint>
98+
</configuration>
99+
</plugin>
100+
</plugins>
101+
</build>
102+
103+
</project>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2005-2017 Red Hat, Inc.
5+
6+
Red Hat licenses this file to you under the Apache License, version
7+
2.0 (the "License"); you may not use this file except in compliance
8+
with the License. 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
15+
implied. See the License for the specific language governing
16+
permissions and limitations under the License.
17+
18+
-->
19+
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="
22+
http://www.osgi.org/xmlns/blueprint/v1.0.0 https://osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
23+
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/spring/camel-blueprint.xsd">
24+
25+
<camelContext id="camel" xmlns="http://camel.apache.org/schema/blueprint">
26+
27+
<!--
28+
Route which will execute the select query every 20s and display result in the log
29+
-->
30+
<route id="trigger-database">
31+
<from uri="timer://webinar?delay=4000&amp;period=20000" />
32+
<setBody>
33+
<constant>SELECT * FROM REPORT.T_INCIDENT</constant>
34+
</setBody>
35+
<to uri="jdbc:reportdb" />
36+
<split>
37+
<simple>${body}</simple>
38+
<log message="*** Select all : ${body}" />
39+
</split>
40+
</route>
41+
42+
<!--
43+
Route which will execute the select query when a file will be poll from
44+
data directory. this file contains the keys of the incidents to be find
45+
and display result in the log
46+
-->
47+
<route id="key-from-file">
48+
<from uri="file://target/data" />
49+
<split>
50+
<tokenize token="," />
51+
<setBody>
52+
<simple>SELECT * FROM REPORT.T_INCIDENT WHERE INCIDENT_REF = '${body}'</simple>
53+
</setBody>
54+
<log message=">>> SQL Query : ${body}" />
55+
<to uri="jdbc:reportdb" />
56+
<log message=">>> Select using key : ${body}" />
57+
</split>
58+
</route>
59+
60+
</camelContext>
61+
62+
<!-- PostgreSQL DB -->
63+
<bean id="reportdb" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
64+
<property name="driverClassName" value="org.postgresql.Driver" />
65+
<property name="url" value="jdbc:postgresql://localhost:5432/reportdb" />
66+
<property name="username" value="fuse" />
67+
<property name="password" value="fuse" />
68+
</bean>
69+
70+
</blueprint>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright 2005-2017 Red Hat, Inc.
3+
#
4+
# Red Hat licenses this file to you under the Apache License, version
5+
# 2.0 (the "License"); you may not use this file except in compliance
6+
# with the License. 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
13+
# implied. See the License for the specific language governing
14+
# permissions and limitations under the License.
15+
#
16+
17+
selectReportWithIds=SELECT * FROM REPORT.T_INCIDENT WHERE INCIDENT_REF = '001' OR INCIDENT_REF = '002'
18+
timerParams=delay=1000&period=10000

0 commit comments

Comments
 (0)