Overview
Cojan van Ballegooijen, Red Hat Senior Solution Architect, Bill Kemp, Red Hat Senior Solution Architect, and myself have created an example around a Customer Context Use Case to show how to use the Camel Components in Fuse to access a Data Virtualization Virtual Database (VDB). The data service provides the customer context which is aggregated data from a XML file and CSV file. The data on each customer provides the name, the credit score, the number of calls the customer has placed to customer support and the sentiment (Hot, Cold, Warm) toward the company from social media. We will review the components and show how to run the demo. The demo repository is located in jbossdemocentral on github. In our project directory we have the individual use cases which are built and deployed when running the scripts. The Teiid jdbc jar is loaded into the profile with wrap file during the run script.
Use Case 1 - JDBC Component
blueprint.xml design view |
blueprint.xml source view with the query property and datasource properties |
JDBC Component excerpt from the Camel Component Page:
The jdbc component enables you to access databases through JDBC, where SQL queries (SELECT) and operations (INSERT, UPDATE, etc) are sent in the message body. This component uses the standard JDBC API, unlike the Camel SQL Component component, which uses spring-jdbc.
Maven users will need to add thecamel-jdbc dependency to their pom.xml for this component. This component can only be used to define producer endpoints, which means that you cannot use the JDBC component in a from() statement. The URI Format for the JDBC component is:
jdbc:dataSourceName[?options]
This component only supports producer endpoints. You can append query options to the URI in the following format, ?option=value&option=value&...
Use Case 2 - SQL Component
The second use case is similar to the first in that a timer component runs a query every 60 seconds, the results from the query are then split into individual records and then sent to the log. Also we are using the Blueprint DSL in the blueprint.xml. The difference with the SQL component is the query is part of the URI of the component. Also we are loading the datasource into the SqlComponent class.
blueprint.xml design view |
blueprint.xml source view of SqlComponent with datasource reference |
The sql: component allows you to work with databases using JDBC queries. The difference between this component and JDBC component is that in case of SQL the query is a property of the endpoint and it uses message payload as parameters passed to the query. From Camel 2.11 onwards this component can create both consumer (e.g. from()) and producer endpoints (e.g. to()). In previous versions, it could only act as a producer.
This component uses spring-jdbc behind the scenes for the actual SQL handling. Maven users will need to add the camel-sql dependency to their pom.xml for this component. The SQL component also supports:
- a JDBC based repository for the Idempotent Consumer EIP pattern.
- a JDBC based repository for the Aggregator EIP pattern.
The SQL component uses the following endpoint URI notation:
sql:select * from table where id=# order by name[?options]
You can append query options to the URI in the following format, ?option=value&option=value&...
sql:select * from table where id=# order by name[?options]
You can append query options to the URI in the following format, ?option=value&option=value&...
Use Case 3 - Olingo Component
The Olingo component will be a part of Fuse 6.2 so we decided to wait until that release in order to document and add this component to this demo. You can try an example with Camel 2.14 which we have in the https://github.com/jbossdemocentral/dv-fuse-integration-demo/tree/master/projects/DVWorkspacewithFuseTest/olingo2 folder of the project. We will cover in more detail in a follow up article for the Olingo component.
Olingo Component excerpt from Camel Component Page:
The Olingo2 component utilizes Apache Olingo version 2.0 APIs to interact with OData 2.0 and 3.0 compliant services. A number of popular commercial and enterprise vendors and products support the OData protocol. A sample list of supporting products can be found on the OData website.
Maven users will need to add the camel-olingo2 dependency to their pom.xml for this component. The URI format for the Olingo component is:
olingo2://endpoint/?[options]
Use Case 4 - JETTY Component for a REST Service
For Use Case 4 we use a REST service to expose the OData Data Virtualization Service.
blueprint.xml design view |
blueprint.xml source view of the route |
Jetty Component excerpt from the Camel Component Page:
The jetty component provides HTTP-based endpoints for consuming and producing HTTP requests. That is, the Jetty component behaves as a simple Web server. Jetty can also be used as a http client which mean you can also use it with Camel as a producer.Maven users will need to add the camel-jetty dependency to their pom.xml for this component. The URI format is:
jetty:http://hostname[:port][/resourceUri][?options]
You can append query options to the URI in the following format, ?option=value&option=value&...
Running the Project
Step 1: Download and unzip the repository or Clone the repository. If running on Windows, it is reccommended the project be extracted to a location near the root drive path due to limitations of length of file/path names.
Step 2: Add the DV and Fuse Products to the software directory. You can download them from the Customer Support Portal (CSP) or jboss.org.
Step 3: Run 'init.sh' or 'init.bat' to setup the environment locally. 'init.bat' must be run with Administrative privileges.
Step 4: Run 'run.sh' or 'run.bat' to start the servers, create the container and deploy the bundles.
Step 5: Sign onto the Fuse Management console, http://localhost:8181, with the admin user and check the console log to see the output from the routes for the use cases. You can also view the Camel Diagrams. Browse to http://localhost:9000/usecase4 to see the data for Use Case 4 through Jetty.
The demo can be run in a docker container in addition to a local install. Full instructions can be found in support/docker/README.md of the project.