Modified: websites/production/camel/content/tracer-example.html
==============================================================================
--- websites/production/camel/content/tracer-example.html (original)
+++ websites/production/camel/content/tracer-example.html Fri Aug 25 08:22:01 
2017
@@ -36,18 +36,6 @@
     <![endif]-->
 
 
-  <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css' 
rel='stylesheet' type='text/css' />
-  <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css' 
rel='stylesheet' type='text/css' />
-  <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js' 
type='text/javascript'></script>
-  <script src='//camel.apache.org/styles/highlighter/scripts/shBrushSql.js' 
type='text/javascript'></script>
-  <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js' 
type='text/javascript'></script>
-  <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js' 
type='text/javascript'></script>
-  <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js' 
type='text/javascript'></script>
-  
-  <script type="text/javascript">
-  SyntaxHighlighter.defaults['toolbar'] = false;
-  SyntaxHighlighter.all();
-  </script>
 
     <title>
     Apache Camel: Tracer Example
@@ -87,106 +75,10 @@
        <tbody>
         <tr>
         <td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 
id="TracerExample-TracerExample">Tracer Example</h2><h3 
id="TracerExample-Introduction">Introduction</h3><p>This example demonstrates 
the <a shape="rect" href="tracer.html">Tracer</a>. <a shape="rect" 
href="tracer.html">Tracer</a> is a tracing feature build in camel core to log 
snapshots of <a shape="rect" href="exchange.html">Exchange</a>s while they are 
routed. This allows you to see:</p><ul class="alternate"><li>how a given <a 
shape="rect" href="exchange.html">Exchange</a> was routed</li><li>a snapshot of 
the content of the <a shape="rect" href="exchange.html">Exchange</a> at any 
given node it passed in the route</li></ul><p>When used Camel will by default 
log the snapshot at&#160;<strong><code>INFO</code></strong> level. This example 
demonstrates how to persist trace snapshots using <a shape="rect" 
href="jpa.html">JPA</a> 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.</p><h3 
id="TracerExample-Requirements">Requirements</h3><p>This requires Camel 2.0, 
the&#160;<strong><code>camel-jpa</code></strong> component and configuration of 
the target database.</p><h3 id="TracerExample-DataModel">Data 
Model</h3><p>Camel uses the 
<strong><code>org.apache.camel.processor.interceptor.JpaTraceEventMessage</code></strong>
 JPA @Entity as data model. This class has been enhanced with <a shape="rect" 
href="jpa.html">JPA</a> annotations.</p><p>The class has the following 
properties in the <a shape="rect" href="jpa.html">JPA</a> model:</p><div 
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" 
rowspan="1" class="confluenceTh"><p>Property</p></th><th colspan="1" 
rowspan="1" class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1" 
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>Body</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>S
 tring</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The 
<a shape="rect" 
href="exchange.html">Exchange</a>&#160;<strong><code>IN</code></strong> body 
dumped as a <strong><code>String</code></strong>.</p></td></tr><tr><td 
colspan="1" rowspan="1" 
class="confluenceTd"><p><code>BodyType</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>The <a shape="rect" 
href="exchange.html">Exchange</a>&#160;<strong><code>IN</code></strong> body 
java type such as <strong><code>String</code></strong>, 
<strong><code>org.w3c.Document</code></strong>,&#160;<strong><code>com.mycompany.MyOrder</code></strong>
 etc.</p></td></tr><tr><td colspan="1" rowspan="1" 
class="confluenceTd"><p><code>CausedByException</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>The <a shape="rect" href="exchange.html">Ex
 change</a> exception (if any) dumped as a String including 
stacktrace.</p></td></tr><tr><td colspan="1" rowspan="1" 
class="confluenceTd"><p><code>ExchangeId</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>Unique id of the <a shape="rect" 
href="exchange.html">Exchange.</a></p></td></tr><tr><td colspan="1" rowspan="1" 
class="confluenceTd"><p><code>ExchangePattern</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>The <a shape="rect" 
href="exchange-pattern.html">Exchange Pattern</a> such 
as&#160;<strong><code>InOnly</code></strong> or 
<strong><code>InOut</code></strong>.</p></td></tr><tr><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>FromEndpoint</code></p></td><td 
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td 
colspan="1" rowspan="1" class="confluenc
 eTd"><p>the URI of the starting consumer the <a shape="rect" 
href="exchange.html">Exchange</a> was created (usually a from in the 
route).</p></td></tr><tr><td colspan="1" rowspan="1" 
class="confluenceTd"><p><code>Headers</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>The <a shape="rect" 
href="exchange.html">Exchange</a>&#160;<strong><code>IN</code></strong> headers 
dumped as a <strong><code>String</code></strong>.</p></td></tr><tr><td 
colspan="1" rowspan="1" class="confluenceTd"><p><code>Id</code></p></td><td 
colspan="1" rowspan="1" class="confluenceTd"><p><code>Long</code></p></td><td 
colspan="1" rowspan="1" class="confluenceTd"><p>Primary key that is generated 
by the database.</p></td></tr><tr><td colspan="1" rowspan="1" 
class="confluenceTd"><p><code>OutBody</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" cla
 ss="confluenceTd"><p>The <a shape="rect" 
href="exchange.html">Exchange</a>&#160;<strong><code>OUT</code></strong> body 
(if any) dumped as a <strong><code>String</code></strong>.</p></td></tr><tr><td 
colspan="1" rowspan="1" 
class="confluenceTd"><p><code>OutBodyType</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>The <a shape="rect" 
href="exchange.html">Exchange</a>&#160;<strong><code>OUT</code></strong> body 
(if any) java type such as <strong><code>String</code></strong>, 
<strong><code>org.w3c.Document</code></strong>,&#160;<strong><code>com.mycompany.MyOrder</code></strong>
 etc.</p></td></tr><tr><td colspan="1" rowspan="1" 
class="confluenceTd"><p><code>OutHeaders</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>The <a shape="rect" 
href="exchange.html">Exchange</a>&#160;<strong><code>OUT</c
 ode></strong> (if any) headers dumped as a 
<strong><code>String</code></strong>.</p></td></tr><tr><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>PreviousNode</code></p></td><td 
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td 
colspan="1" rowspan="1" 
class="confluenceTd"><p><strong><code>id</code></strong> of the previous step 
in the route. Is <strong><code>null</code></strong> if there wasn't a previous 
node such as the start.</p></td></tr><tr><td colspan="1" rowspan="1" 
class="confluenceTd"><p><code>Properties</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>The <a shape="rect" 
href="exchange.html">Exchange</a> properties dumped as a 
<strong><code>String</code></strong>.</p></td></tr><tr><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>ShortExchangeId</code></p></td><td 
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code
 ></p></td><td colspan="1" rowspan="1" 
 >class="confluenceTd"><p><strong><code>id</code></strong> of the <a 
 >shape="rect" href="exchange.html">Exchange</a> without the machine 
 >name.</p></td></tr><tr><td colspan="1" rowspan="1" 
 >class="confluenceTd"><p><code>Timestamp</code></p></td><td colspan="1" 
 >rowspan="1" class="confluenceTd"><p><code>Date</code></p></td><td colspan="1" 
 >rowspan="1" class="confluenceTd"><p>Timestamp when the snapshot was 
 >generated. Is the system time of the JMV in which Camel is 
 >running.</p></td></tr><tr><td colspan="1" rowspan="1" 
 >class="confluenceTd"><p><code>ToNode</code></p></td><td colspan="1" 
 >rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td 
 >colspan="1" rowspan="1" 
 >class="confluenceTd"><p><strong><code>id</code></strong> of the next step in 
 >the route.</p></td></tr></tbody></table></div><p>The table name for 
 >persisting trace events is: 
 ><strong><code>CAMEL_MESSAGETRACED</code></strong></p><h3 
 >id="TracerExample-Configurationofthedatabase">Configur
 ation of the database</h3><p>The <a shape="rect" href="tracer.html">Tracer</a> 
uses standard <a shape="rect" href="jpa.html">JPA</a> configuration for setting 
the database. In 
the&#160;<strong><code>META-INF/persistence.xml</code></strong> file we setup 
the service unit and the database configuration as:</p><div class="code panel 
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[
-&lt;persistence xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot;
-             xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
-             version=&quot;1.0&quot;&gt;
-
-  &lt;persistence-unit name=&quot;tracer&quot; 
transaction-type=&quot;RESOURCE_LOCAL&quot;&gt;
-    
&lt;class&gt;org.apache.camel.processor.interceptor.jpa.JpaTraceEventMessage&lt;/class&gt;
-
-    &lt;properties&gt;
-      &lt;property name=&quot;hibernate.dialect&quot; 
value=&quot;org.apache.camel.example.tracer.FixedDerbyDialect&quot;/&gt;
-      &lt;property name=&quot;hibernate.connection.driver_class&quot; 
value=&quot;org.apache.derby.jdbc.EmbeddedDriver&quot;/&gt;
-      &lt;property name=&quot;hibernate.connection.url&quot; 
value=&quot;jdbc:derby:target/derby;create=true&quot;/&gt;
-      &lt;property name=&quot;hibernate.hbm2ddl.auto&quot; 
value=&quot;create&quot;/&gt;
-
-      &lt;!-- debugging flags --&gt;
-      &lt;!-- &lt;property name=&quot;hibernate.show_sql&quot; 
value=&quot;true&quot;/&gt;
-      &lt;property name=&quot;hibernate.format_sql&quot; 
value=&quot;true&quot;/&gt; --&gt;
-    &lt;/properties&gt;
-
-  &lt;/persistence-unit&gt;
-&lt;/persistence&gt;
-]]></script>
-</div></div>What is important is to add 
the&#160;<strong><code>JpaTraceEventMessage</code></strong> as a class in the 
<strong><code>persistence.xml</code></strong> file to register our data 
model:<div class="code panel pdl" style="border-width: 1px;"><div 
class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[&lt;class&gt;org.apache.camel.processor.interceptor.JpaTraceEventMessage&lt;/class&gt;
-]]></script>
-</div></div><p>In this example we use Hibernate JPA and a HSQLDB as 
database.</p><h3 id="TracerExample-RunningtheExample">Running the 
Example</h3><p>The <strong><code>README.txt</code></strong> states how to run 
the example from either ANT or Maven.</p><p>Here we show running with 
Maven:</p><div class="code panel pdl" style="border-width: 1px;"><div 
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[mvn camel:run
-]]></script>
-</div></div><p>When the application starts it start:</p><ul 
class="alternate"><li>in the console</li><li>a GUI for browsing the SQL 
database</li></ul><p>Select the console where the application should prompt you 
to enter some words. Try entering: <strong><code>Camel</code></strong>. The 
application should respond with a text quote.</p><p>You can also enter multiple 
quotes separate with space, and the response should be the best quote based on 
the list of words given. See the file 
<strong><code>src/main/resources/META-INF/spring/camel-context.xml</code></strong>
 to give you an idea how it works.</p><p>You can enter: <strong><code>Camel 
Beer</code></strong> and it should be smart enough to find a quote for the beer 
<img class="emoticon emoticon-wink" 
src="https://cwiki.apache.org/confluence/s/en_GB/5997/6f42626d00e36f53fe51440403446ca61552e2a2.1/_/images/icons/emoticons/wink.png";
 data-emoticon-name="wink" alt="(wink)"></p><h3 
id="TracerExample-SeeingtheTraceEvents">Seeing the Trace Ev
 ents</h3><p>When the program was started a GUI application was started as 
well. Its a SQL prompt for the database. So try entering:</p><div class="code 
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: sql; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[select * from camel_messagetraced
-]]></script>
-</div></div><p>And it should return the list of trace events in the 
SQL.</p><p>We enter this SQL:</p><div class="code panel pdl" 
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: sql; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[select id, shortExchangeId, previousNode, 
toNode, body from camel_messagetraced]]></script>
-</div></div><p>and get the output as the picture below:</p><p><br 
clear="none"> <span class="confluence-embedded-file-wrapper"><img 
class="confluence-embedded-image" src="tracer-example.data/tracer_sql.png" 
data-image-src="/confluence/download/attachments/107823/tracer_sql.png?version=1&amp;modificationDate=1232323775000&amp;api=v2"
 data-unresolved-comment-count="0" data-linked-resource-id="9605" 
data-linked-resource-version="1" data-linked-resource-type="attachment" 
data-linked-resource-default-alias="tracer_sql.png" 
data-base-url="https://cwiki.apache.org/confluence"; 
data-linked-resource-content-type="image/png" 
data-linked-resource-container-id="107823" 
data-linked-resource-container-version="26"></span></p><h3 
id="TracerExample-Routing">Routing</h3><p>The diagram below illustrates the 
route diagram generated using <a shape="rect" 
href="visualisation.html">Visualisation</a>.<br clear="none"> <span 
class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" 
src
 ="tracer-example.data/tracer_dot.png" 
data-image-src="/confluence/download/attachments/107823/tracer_dot.png?version=1&amp;modificationDate=1232326207000&amp;api=v2"
 data-unresolved-comment-count="0" data-linked-resource-id="9606" 
data-linked-resource-version="1" data-linked-resource-type="attachment" 
data-linked-resource-default-alias="tracer_dot.png" 
data-base-url="https://cwiki.apache.org/confluence"; 
data-linked-resource-content-type="image/png" 
data-linked-resource-container-id="107823" 
data-linked-resource-container-version="26"></span></p><p>We receive an 
Exchange from the in stream, then its split using the 
<strong><code>splitWords</code></strong> method. Then the quote method is 
invoked before it's aggregated and finally sent to the stream out to be printed 
in the console.</p><h3 id="TracerExample-TracetheRouting">Trace the 
Routing</h3><p>If we look at the 6 rows from the traced SQL (the first picture) 
and with the route diagram in mind we can get a better understand how the
  <a shape="rect" href="exchange.html">Exchange</a> was routed.</p><ol><li>The 
<a shape="rect" href="exchange.html">Exchange</a> does not have a previousNode 
so its the first step where its consumed from the input stream and that its 
going to the splitter.</li><li>The exchange id has changed and this is the 
output of the splitter as it creates a new Exchange. We can also see this one 
has one word in the body. This <a shape="rect" 
href="exchange.html">Exchange</a> is being routed to the quote bean 
next.</li><li>This is the 2nd output from the splitter containing the 2nd word. 
This <a shape="rect" href="exchange.html">Exchange</a> is being routed to the 
quote bean next.</li><li>This is the Beer <a shape="rect" 
href="exchange.html">Exchange</a> where we can see the output from the quote 
server and that its being routed to the aggregator.</li><li>This is the Camel 
<a shape="rect" href="exchange.html">Exchange</a> where we can see the output 
from the quote server and that its being routed
  to the aggregator.</li><li>This is the result of the aggregator where the <a 
shape="rect" href="exchange.html">Exchange</a> ending with 
id&#160;<strong><code>0-2</code></strong> "was the winner" and is being routed 
as the aggregated result to the stream out.</li></ol><h3 
id="TracerExample-ConfigurationofTracinginCamel">Configuration of <a 
shape="rect" href="jpa.html">JPA</a> Tracing in Camel</h3><p>In Camel you need 
to configure it to use JPA for tracing. We do this as by adding a tracer in the 
<strong><code>META-INF/camel-context.mxl</code></strong> file:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[
-&lt;!-- use camel jpa trace so we can see all the traced exchanges in a 
database --&gt;
-&lt;bean id=&quot;camelTracer&quot; 
class=&quot;org.apache.camel.processor.interceptor.Tracer&quot;&gt;
-  &lt;!-- turn on jpa tracing, otherwise the TraceEventMessage is a non JPA 
Entity class --&gt;
-  &lt;property name=&quot;useJpa&quot; value=&quot;true&quot;/&gt;
-  &lt;!-- the destination to send the traced messages --&gt;
-  &lt;property name=&quot;destination&quot; ref=&quot;traced&quot;/&gt;
-  &lt;!-- we turn ordinary trace logging off so we only see the traced 
messages in the database,
-       but you can have both if you like --&gt;
-  &lt;property name=&quot;logLevel&quot; value=&quot;OFF&quot;/&gt;
-&lt;/bean&gt;
-]]></script>
-</div></div>To properly configure <a shape="rect" href="jpa.html">JPA</a> for 
tracing we must complete these two steps:<ol><li>Enable the <a shape="rect" 
href="jpa.html">JPA</a> tracing by setting the property 
<strong><code>useJpa=true</code></strong>.</li><li>Set the destination 
or&#160;<strong><code>destinationUri</code></strong> to a <a shape="rect" 
href="jpa.html">JPA</a> producer endpoint.</li></ol><p>In this example we set 
the destintation to refer to an endpoint defined in the camel context:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[
-&lt;endpoint id=&quot;traced&quot; 
uri=&quot;jpa://org.apache.camel.processor.interceptor.JpaTraceEventMessage?persistenceUnit=tracer&quot;/&gt;
-]]></script>
-</div></div>Here it's important that the endpoint is configure with 
the&#160;<strong><code>org.apache.camel.processor.interceptor.JpaTraceEventMessage</code></strong>
 as entity name and the&#160;<strong><code>persistenceUnit</code></strong> as 
an option. In out example we use tracer.<p>Then the following is standard 
Spring <a shape="rect" href="jpa.html">JPA</a> configuration:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[
-&lt;!-- this is ordinary JPA spring configuration --&gt;
-&lt;bean id=&quot;transactionTemplate&quot; 
class=&quot;org.springframework.transaction.support.TransactionTemplate&quot;&gt;
-  &lt;property name=&quot;transactionManager&quot;&gt;
-    &lt;bean 
class=&quot;org.springframework.orm.jpa.JpaTransactionManager&quot;&gt;
-      &lt;property name=&quot;entityManagerFactory&quot; 
ref=&quot;entityManagerFactory&quot;/&gt;
-    &lt;/bean&gt;
-  &lt;/property&gt;
-&lt;/bean&gt;
-
-&lt;!-- this is ordinary JPA spring configuration --&gt;
-&lt;bean id=&quot;entityManagerFactory&quot; 
class=&quot;org.springframework.orm.jpa.LocalEntityManagerFactoryBean&quot;&gt;
-  &lt;!-- we have named our presistence unit tracer in the 
META-INF/persistence.xml file --&gt;
-  &lt;property name=&quot;persistenceUnitName&quot; 
value=&quot;tracer&quot;/&gt;
-&lt;/bean&gt;
-]]></script>
-</div></div>However we must set 
the&#160;<strong><code>persistenceUnitName</code></strong> to the same unit 
name we defined in <strong><code>persistence.xml</code></strong>, such as 
<strong><code>tracer</code></strong> as we are using in this example.<p>And if 
you are wondering how the Camel route is defined then its here:</p><div 
class="code panel pdl" style="border-width: 1px;"><div class="codeContent 
panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default" 
type="syntaxhighlighter"><![CDATA[
-&lt;route&gt;
-  &lt;!-- in stream to allow you to enter some text in the console --&gt;
-  &lt;from 
uri=&quot;stream:in?initialPromptDelay=4000&amp;amp;promptDelay=2000&amp;amp;promptMessage=Enter
 some words:&quot;/&gt;
-
-  &lt;!-- split the text --&gt;
-  &lt;split&gt;
-    &lt;!-- use methodCall expression to split the words, using a java bean to 
do it --&gt;
-    &lt;method bean=&quot;quoteService&quot; method=&quot;splitWords&quot;/&gt;
-
-    &lt;!-- for each split message invoke the quote server to get a quote of 
the word --&gt;
-    &lt;to uri=&quot;bean:quoteService?method=quote&quot;/&gt;
-
-    &lt;!-- now we need to find the best quote, so we aggregate all the 
splitted words
-         we use our own strategy how to aggregate --&gt;
-    &lt;aggregate strategyRef=&quot;myAggregateStrategy&quot;&gt;
-      &lt;!-- correlate everything using constant true, as they are all from 
the same source --&gt;
-      &lt;correlationExpression&gt;
-        &lt;constant&gt;true&lt;/constant&gt;
-      &lt;/correlationExpression&gt;
-      &lt;!-- complete after 1 sec on inactivity --&gt;
-      &lt;completionTimeout&gt;
-        &lt;constant&gt;1000&lt;/constant&gt;
-      &lt;/completionTimeout&gt;
-      &lt;!-- send the result to stream out so we can see the response in the 
console --&gt;
-      &lt;to uri=&quot;stream:out&quot;/&gt;
-    &lt;/aggregate&gt;
-  &lt;/split&gt;
-&lt;/route&gt;
-]]></script>
-</div></div><h3 id="TracerExample-Seealso">See also</h3><ul 
class="alternate"><li><a shape="rect" href="tracer.html">Tracer</a></li><li><a 
shape="rect" href="examples.html">Examples</a></li><li><a shape="rect" 
href="tutorials.html">Tutorials</a></li><li><a shape="rect" 
href="user-guide.html">User Guide</a></li></ul></div>
+<div class="wiki-content maincontent"><h2 
id="TracerExample-TracerExample">Tracer Example</h2><h3 
id="TracerExample-Introduction">Introduction</h3><p>This example demonstrates 
the <a shape="rect" href="tracer.html">Tracer</a>. <a shape="rect" 
href="tracer.html">Tracer</a> is a tracing feature build in camel core to log 
snapshots of <a shape="rect" href="exchange.html">Exchange</a>s while they are 
routed. This allows you to see:</p><ul class="alternate"><li>how a given <a 
shape="rect" href="exchange.html">Exchange</a> was routed</li><li>a snapshot of 
the content of the <a shape="rect" href="exchange.html">Exchange</a> at any 
given node it passed in the route</li></ul><p>When used Camel will by default 
log the snapshot at&#160;<strong><code>INFO</code></strong> level. This example 
demonstrates how to persist trace snapshots using <a shape="rect" 
href="jpa.html">JPA</a> 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.</p><h3 
id="TracerExample-Requirements">Requirements</h3><p>This requires Camel 2.0, 
the&#160;<strong><code>camel-jpa</code></strong> component and configuration of 
the target database.</p><h3 id="TracerExample-DataModel">Data 
Model</h3><p>Camel uses the 
<strong><code>org.apache.camel.processor.interceptor.JpaTraceEventMessage</code></strong>
 JPA @Entity as data model. This class has been enhanced with <a shape="rect" 
href="jpa.html">JPA</a> annotations.</p><p>The class has the following 
properties in the <a shape="rect" href="jpa.html">JPA</a> model:</p><div 
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1" 
rowspan="1" class="confluenceTh"><p>Property</p></th><th colspan="1" 
rowspan="1" class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1" 
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>Body</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>S
 tring</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The 
<a shape="rect" 
href="exchange.html">Exchange</a>&#160;<strong><code>IN</code></strong> body 
dumped as a <strong><code>String</code></strong>.</p></td></tr><tr><td 
colspan="1" rowspan="1" 
class="confluenceTd"><p><code>BodyType</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>The <a shape="rect" 
href="exchange.html">Exchange</a>&#160;<strong><code>IN</code></strong> body 
java type such as <strong><code>String</code></strong>, 
<strong><code>org.w3c.Document</code></strong>,&#160;<strong><code>com.mycompany.MyOrder</code></strong>
 etc.</p></td></tr><tr><td colspan="1" rowspan="1" 
class="confluenceTd"><p><code>CausedByException</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>The <a shape="rect" href="exchange.html">Ex
 change</a> exception (if any) dumped as a String including 
stacktrace.</p></td></tr><tr><td colspan="1" rowspan="1" 
class="confluenceTd"><p><code>ExchangeId</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>Unique id of the <a shape="rect" 
href="exchange.html">Exchange.</a></p></td></tr><tr><td colspan="1" rowspan="1" 
class="confluenceTd"><p><code>ExchangePattern</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>The <a shape="rect" 
href="exchange-pattern.html">Exchange Pattern</a> such 
as&#160;<strong><code>InOnly</code></strong> or 
<strong><code>InOut</code></strong>.</p></td></tr><tr><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>FromEndpoint</code></p></td><td 
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td 
colspan="1" rowspan="1" class="confluenc
 eTd"><p>the URI of the starting consumer the <a shape="rect" 
href="exchange.html">Exchange</a> was created (usually a from in the 
route).</p></td></tr><tr><td colspan="1" rowspan="1" 
class="confluenceTd"><p><code>Headers</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>The <a shape="rect" 
href="exchange.html">Exchange</a>&#160;<strong><code>IN</code></strong> headers 
dumped as a <strong><code>String</code></strong>.</p></td></tr><tr><td 
colspan="1" rowspan="1" class="confluenceTd"><p><code>Id</code></p></td><td 
colspan="1" rowspan="1" class="confluenceTd"><p><code>Long</code></p></td><td 
colspan="1" rowspan="1" class="confluenceTd"><p>Primary key that is generated 
by the database.</p></td></tr><tr><td colspan="1" rowspan="1" 
class="confluenceTd"><p><code>OutBody</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" cla
 ss="confluenceTd"><p>The <a shape="rect" 
href="exchange.html">Exchange</a>&#160;<strong><code>OUT</code></strong> body 
(if any) dumped as a <strong><code>String</code></strong>.</p></td></tr><tr><td 
colspan="1" rowspan="1" 
class="confluenceTd"><p><code>OutBodyType</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>The <a shape="rect" 
href="exchange.html">Exchange</a>&#160;<strong><code>OUT</code></strong> body 
(if any) java type such as <strong><code>String</code></strong>, 
<strong><code>org.w3c.Document</code></strong>,&#160;<strong><code>com.mycompany.MyOrder</code></strong>
 etc.</p></td></tr><tr><td colspan="1" rowspan="1" 
class="confluenceTd"><p><code>OutHeaders</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>The <a shape="rect" 
href="exchange.html">Exchange</a>&#160;<strong><code>OUT</c
 ode></strong> (if any) headers dumped as a 
<strong><code>String</code></strong>.</p></td></tr><tr><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>PreviousNode</code></p></td><td 
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td 
colspan="1" rowspan="1" 
class="confluenceTd"><p><strong><code>id</code></strong> of the previous step 
in the route. Is <strong><code>null</code></strong> if there wasn't a previous 
node such as the start.</p></td></tr><tr><td colspan="1" rowspan="1" 
class="confluenceTd"><p><code>Properties</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" 
rowspan="1" class="confluenceTd"><p>The <a shape="rect" 
href="exchange.html">Exchange</a> properties dumped as a 
<strong><code>String</code></strong>.</p></td></tr><tr><td colspan="1" 
rowspan="1" class="confluenceTd"><p><code>ShortExchangeId</code></p></td><td 
colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code
 ></p></td><td colspan="1" rowspan="1" 
 >class="confluenceTd"><p><strong><code>id</code></strong> of the <a 
 >shape="rect" href="exchange.html">Exchange</a> without the machine 
 >name.</p></td></tr><tr><td colspan="1" rowspan="1" 
 >class="confluenceTd"><p><code>Timestamp</code></p></td><td colspan="1" 
 >rowspan="1" class="confluenceTd"><p><code>Date</code></p></td><td colspan="1" 
 >rowspan="1" class="confluenceTd"><p>Timestamp when the snapshot was 
 >generated. Is the system time of the JMV in which Camel is 
 >running.</p></td></tr><tr><td colspan="1" rowspan="1" 
 >class="confluenceTd"><p><code>ToNode</code></p></td><td colspan="1" 
 >rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td 
 >colspan="1" rowspan="1" 
 >class="confluenceTd"><p><strong><code>id</code></strong> of the next step in 
 >the route.</p></td></tr></tbody></table></div><p>The table name for 
 >persisting trace events is: 
 ><strong><code>CAMEL_MESSAGETRACED</code></strong></p><h3 
 >id="TracerExample-Configurationofthedatabase">Configur
 ation of the database</h3><p>The <a shape="rect" href="tracer.html">Tracer</a> 
uses standard <a shape="rect" href="jpa.html">JPA</a> configuration for setting 
the database. In 
the&#160;<strong><code>META-INF/persistence.xml</code></strong> file we setup 
the service unit and the database configuration 
as:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/examples/camel-example-tracer/src/main/resources/META-INF/persistence.xml}</plain-text-body>What
 is important is to add 
the&#160;<strong><code>JpaTraceEventMessage</code></strong> as a class in the 
<strong><code>persistence.xml</code></strong> file to register our data 
model:</p><parameter 
ac:name="">xml</parameter><plain-text-body>&lt;class&gt;org.apache.camel.processor.interceptor.JpaTraceEventMessage&lt;/class&gt;
+</plain-text-body><p>In this example we use Hibernate JPA and a HSQLDB as 
database.</p><h3 id="TracerExample-RunningtheExample">Running the 
Example</h3><p>The <strong><code>README.txt</code></strong> states how to run 
the example from either ANT or Maven.</p><p>Here we show running with 
Maven:</p><plain-text-body>mvn camel:run
+</plain-text-body><p>When the application starts it start:</p><ul 
class="alternate"><li>in the console</li><li>a GUI for browsing the SQL 
database</li></ul><p>Select the console where the application should prompt you 
to enter some words. Try entering: <strong><code>Camel</code></strong>. The 
application should respond with a text quote.</p><p>You can also enter multiple 
quotes separate with space, and the response should be the best quote based on 
the list of words given. See the file 
<strong><code>src/main/resources/META-INF/spring/camel-context.xml</code></strong>
 to give you an idea how it works.</p><p>You can enter: <strong><code>Camel 
Beer</code></strong> and it should be smart enough to find a quote for the beer 
<img class="emoticon emoticon-wink" 
src="https://cwiki.apache.org/confluence/s/en_GB/5997/6f42626d00e36f53fe51440403446ca61552e2a2.1/_/images/icons/emoticons/wink.png";
 data-emoticon-name="wink" alt="(wink)"></p><h3 
id="TracerExample-SeeingtheTraceEvents">Seeing the Tr
 ace Events</h3><p>When the program was started a GUI application was started 
as well. Its a SQL prompt for the database. So try entering:</p><parameter 
ac:name="language">sql</parameter><plain-text-body>select * from 
camel_messagetraced
+</plain-text-body><p>And it should return the list of trace events in the 
SQL.</p><p>We enter this SQL:</p><parameter 
ac:name="language">sql</parameter><plain-text-body>select id, shortExchangeId, 
previousNode, toNode, body from camel_messagetraced</plain-text-body><p>and get 
the output as the picture below:</p><p><br clear="none"> <span 
class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" 
src="tracer-example.data/tracer_sql.png" 
data-image-src="/confluence/download/attachments/107823/tracer_sql.png?version=1&amp;modificationDate=1232323775000&amp;api=v2"
 data-unresolved-comment-count="0" data-linked-resource-id="9605" 
data-linked-resource-version="1" data-linked-resource-type="attachment" 
data-linked-resource-default-alias="tracer_sql.png" 
data-base-url="https://cwiki.apache.org/confluence"; 
data-linked-resource-content-type="image/png" 
data-linked-resource-container-id="107823" 
data-linked-resource-container-version="27"></span></p><h3 id="TracerExample-R
 outing">Routing</h3><p>The diagram below illustrates the route diagram 
generated using <a shape="rect" href="visualisation.html">Visualisation</a>.<br 
clear="none"> <span class="confluence-embedded-file-wrapper"><img 
class="confluence-embedded-image" src="tracer-example.data/tracer_dot.png" 
data-image-src="/confluence/download/attachments/107823/tracer_dot.png?version=1&amp;modificationDate=1232326207000&amp;api=v2"
 data-unresolved-comment-count="0" data-linked-resource-id="9606" 
data-linked-resource-version="1" data-linked-resource-type="attachment" 
data-linked-resource-default-alias="tracer_dot.png" 
data-base-url="https://cwiki.apache.org/confluence"; 
data-linked-resource-content-type="image/png" 
data-linked-resource-container-id="107823" 
data-linked-resource-container-version="27"></span></p><p>We receive an 
Exchange from the in stream, then its split using the 
<strong><code>splitWords</code></strong> method. Then the quote method is 
invoked before it's aggregated and finally sent
  to the stream out to be printed in the console.</p><h3 
id="TracerExample-TracetheRouting">Trace the Routing</h3><p>If we look at the 6 
rows from the traced SQL (the first picture) and with the route diagram in mind 
we can get a better understand how the <a shape="rect" 
href="exchange.html">Exchange</a> was routed.</p><ol><li>The <a shape="rect" 
href="exchange.html">Exchange</a> does not have a previousNode so its the first 
step where its consumed from the input stream and that its going to the 
splitter.</li><li>The exchange id has changed and this is the output of the 
splitter as it creates a new Exchange. We can also see this one has one word in 
the body. This <a shape="rect" href="exchange.html">Exchange</a> is being 
routed to the quote bean next.</li><li>This is the 2nd output from the splitter 
containing the 2nd word. This <a shape="rect" href="exchange.html">Exchange</a> 
is being routed to the quote bean next.</li><li>This is the Beer <a 
shape="rect" href="exchange.html">Excha
 nge</a> where we can see the output from the quote server and that its being 
routed to the aggregator.</li><li>This is the Camel <a shape="rect" 
href="exchange.html">Exchange</a> where we can see the output from the quote 
server and that its being routed to the aggregator.</li><li>This is the result 
of the aggregator where the <a shape="rect" href="exchange.html">Exchange</a> 
ending with id&#160;<strong><code>0-2</code></strong> "was the winner" and is 
being routed as the aggregated result to the stream out.</li></ol><h3 
id="TracerExample-ConfigurationofTracinginCamel">Configuration of <a 
shape="rect" href="jpa.html">JPA</a> Tracing in Camel</h3><p>In Camel you need 
to configure it to use JPA for tracing. We do this as by adding a tracer in the 
<strong><code>META-INF/camel-context.mxl</code></strong> 
file:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/examples/camel-example-tracer/src/main/resources/META-INF/spring/camel-context.xml}</plain-text-body>To
 properly configure 
 <a shape="rect" href="jpa.html">JPA</a> for tracing we must complete these two 
steps:</p><ol><li>Enable the <a shape="rect" href="jpa.html">JPA</a> tracing by 
setting the property <strong><code>useJpa=true</code></strong>.</li><li>Set the 
destination or&#160;<strong><code>destinationUri</code></strong> to a <a 
shape="rect" href="jpa.html">JPA</a> producer endpoint.</li></ol><p>In this 
example we set the destintation to refer to an endpoint defined in the camel 
context:<plain-text-body>{snippet:id=e3|lang=xml|url=camel/trunk/examples/camel-example-tracer/src/main/resources/META-INF/spring/camel-context.xml}</plain-text-body>Here
 it's important that the endpoint is configure with 
the&#160;<strong><code>org.apache.camel.processor.interceptor.JpaTraceEventMessage</code></strong>
 as entity name and the&#160;<strong><code>persistenceUnit</code></strong> as 
an option. In out example we use tracer.</p><p>Then the following is standard 
Spring <a shape="rect" href="jpa.html">JPA</a> configura
 
tion:<plain-text-body>{snippet:id=e2|lang=xml|url=camel/trunk/examples/camel-example-tracer/src/main/resources/META-INF/spring/camel-context.xml}</plain-text-body>However
 we must set the&#160;<strong><code>persistenceUnitName</code></strong> to the 
same unit name we defined in <strong><code>persistence.xml</code></strong>, 
such as <strong><code>tracer</code></strong> as we are using in this 
example.</p><p>And if you are wondering how the Camel route is defined then its 
here:<plain-text-body>{snippet:id=e4|lang=xml|url=camel/trunk/examples/camel-example-tracer/src/main/resources/META-INF/spring/camel-context.xml}</plain-text-body></p><h3
 id="TracerExample-Seealso">See also</h3><ul class="alternate"><li><a 
shape="rect" href="tracer.html">Tracer</a></li><li><a shape="rect" 
href="examples.html">Examples</a></li><li><a shape="rect" 
href="tutorials.html">Tutorials</a></li><li><a shape="rect" 
href="user-guide.html">User Guide</a></li></ul></div>
         </td>
         <td valign="top">
           <div class="navigation">


Reply via email to