Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

The 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: Wiki Markup{snippet:id=e1|lang=xml|url=camel/trunk/examples/camel-example-tracer/src/main/resources/META-INF/persistence.xml}What is important is to add the JpaTraceEventMessage as a class in the persistence.xml file to register our data model:

...

...

In this example we use Hibernate JPA and a HSQLDB as database.

...

Here we show running with Maven:

...

When the application starts it start:

...

When the program was started a GUI application was started as well. Its a SQL prompt for the database. So try entering:

...

...

And it should return the list of trace events in the SQL.

We enter this SQL:

...

...

and get the output as the picture below:

...

In Camel you need to configure it to use JPA for tracing. We do this as by adding a tracer in the META-INF/camel-context.mxl file: Wiki Markup{snippet:id=e1|lang=xml|url=camel/trunk/examples/camel-example-tracer/src/main/resources/META-INF/spring/camel-context.xml}To properly configure JPA for tracing we must complete these two steps:

...

In this example we set the destintation to refer to an endpoint defined in the camel context: Wiki Markup{snippet:id=e3|lang=xml|url=camel/trunk/examples/camel-example-tracer/src/main/resources/META-INF/spring/camel-context.xml}Here it's important that the endpoint is configure with the org.apache.camel.processor.interceptor.JpaTraceEventMessage as entity name and the persistenceUnit as an option. In out example we use tracer.

Then the following is standard Spring JPA configuration: Wiki Markup{snippet:id=e2|lang=xml|url=camel/trunk/examples/camel-example-tracer/src/main/resources/META-INF/spring/camel-context.xml}However we must set the persistenceUnitName to the same unit name we defined in persistence.xml, such as tracer as we are using in this example.

And if you are wondering how the Camel route is defined then its here: Wiki Markup{snippet:id=e4|lang=xml|url=camel/trunk/examples/camel-example-tracer/src/main/resources/META-INF/spring/camel-context.xml}

See also