|
Page Edited :
CAMEL :
Tracer Example
Tracer Example has been edited by Claus Ibsen (Jan 19, 2009). Content:Tracer ExampleIntroductionThis example demonstrates the Tracer. Tracer is a tracing feature build in camel core to log snapshots of Exchanges while they are routed. This allows you to see:
When used Camel will by default log the snapshot at INFO level. This example demonstrates how to persist trace snapshots using JPA into a database. This allows you to store this information and query them from a SQL prompt, giving you full power to analyze the data. RequirementsThis requires Camel 2.0, the camel-jpa component and configuration of the target database. Data ModelCamel uses the org.apache.camel.processor.interceptor.JpaTraceEventMessage JPA @Entity as data model. The class has the following properties in the JPA model:
The table name for persisting trace events is: CAMEL_MESSAGETRACED Configuration of the databaseThe Tracer uses standard JPA configuration for setting the database. In the META-INF/persistence.xml file we setup the service unit and the database configuration as: <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
<persistence-unit name="tracer" transaction-type="RESOURCE_LOCAL">
<class>org.apache.camel.processor.interceptor.JpaTraceEventMessage</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.url" value="jdbc:hsqldb:mem:camel_tracer"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
<!-- debugging flags -->
<!--
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
-->
</properties>
</persistence-unit>
</persistence>
What is important is to add the JpaTraceEventMessage as a class in the persistence.xml file to register our data model: <class>org.apache.camel.processor.interceptor.JpaTraceEventMessage</class> In this example we use Hibernate JPA and a HSQLDB as database. Running the exampleThe README.txt states how to run the example from either ANT or Maven. Here we show running with Maven: mvn camel:run When the application starts it start:
Select the console where the application should prompt you to enter some words. Try entering: Camel You can also enter multiple quotes separate with space, and the response should be the best quote based on the list of words given. You can enter: Camel Beer and it should be smart enough to find a quote for the beer Seeing the trace eventsWhen the program was started a GUI application was started as well. Its a SQL prompt for the database. So try entering: select * from camel_messagetraced And it should return the list of trace events in the SQL. We enter this sql: select id, shortExchangeId, previousNode, toNode, body from camel_messagetraced and get the output as the picture below: See also |
Unsubscribe or edit your notifications preferences
