camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > ControlBus Component
Date Mon, 03 Jun 2013 17:46:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/ControlBus+Component">ControlBus
Component</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (2)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >|| Name || Default Value || Description
|| <br>| {{routeId}} | {{null}} | To specify a route by its {{id}}. | <br></td></tr>
            <tr><td class="diff-changed-lines" >| {{action}} | {{null}} | To denote
an action that can be either: {{start}}, {{stop}}, or {{status}}. To either start or stop
a route, or to get the status of the route as output in the message body. You can use {{suspend}}
and {{resume}} from *Camel 2.11.1* onwards to either suspend or resume a route. <span class="diff-added-words"style="background-color:
#dfd;">And from *Camel 2.11.1* onwards you can use {{stats}} to get performance statics
returned in XML format; the {{routeId}} option can be used to define which route to get the
performance stats for, if {{routeId}} is not defined, then you get statistics for the entire
[CamelContext].</span> | <br></td></tr>
            <tr><td class="diff-unchanged" >| {{async}} | {{false}} | Whether
to execute the control bus task asynchronously. *Important:* If this option is enabled, then
any result from the task is *not* set on the [Exchange]. This is only possible if executing
tasks synchronously. | <br>| {{loggingLevel}} | {{INFO}} | Logging level used for logging
when task is done, or if any exceptions occurred during processing the task. | <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" > <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">h5.
Getting performance statistics <br>*Available as of Camel 2.11.1* <br> <br>This
requires JMX to be enabled (is by default) then you can get the performance statics per route,
or for the [CamelContext]. For example to get the statics for a route named foo, we can do:
<br>{code} <br>String xml = template.requestBody(&quot;controlbus:route?routeId=foo&amp;action=stats&quot;,
null, String.class); <br>{code} <br> <br>The returned statics is in XML
format. Its the same data you can get from JMX with the {{dumpRouteStatsAsXml}} operation
on the {{ManagedRouteMBean}}. <br> <br>To get statics for the entire [CamelContext]
you just omit the routeId parameter as shown below: <br>{code} <br>String xml
= template.requestBody(&quot;controlbus:route?action=stats&quot;, null, String.class);
<br>{code} <br> <br> <br></td></tr>
            <tr><td class="diff-unchanged" >h4. Using [Simple] language <br>
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="ControlBusComponent-ControlBusComponent"></a>ControlBus
Component</h2>
<p><b>Available as of Camel 2.11</b></p>

<p>The <b>controlbus:</b> component provides easy management of Camel applications
based on the <a href="/confluence/display/CAMEL/ControlBus" title="ControlBus">Control
Bus</a> EIP pattern.<br/>
For example, by sending a message to an <a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a>
you can control the lifecycle of routes, or gather performance statistics.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
controlbus:command[?options]
</pre>
</div></div>

<p>Where <b>command</b> can be any string to identify which type of command
to use.</p>

<h3><a name="ControlBusComponent-Commands"></a>Commands </h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Command </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>route</tt> </td>
<td class='confluenceTd'> To control routes using the <tt>routeId</tt> and
<tt>action</tt> parameter. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>language</tt> </td>
<td class='confluenceTd'> Allows you to specify a <a href="/confluence/display/CAMEL/Language"
title="Language">Language</a> to use for evaluating the message body. If there is
any result from the evaluation, then the result is put in the message body. </td>
</tr>
</tbody></table>
</div>
</div>

<h3><a name="ControlBusComponent-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Default Value </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>routeId</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> To specify a route by its <tt>id</tt>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>action</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> To denote an action that can be either: <tt>start</tt>,
<tt>stop</tt>, or <tt>status</tt>. To either start or stop a route,
or to get the status of the route as output in the message body. You can use <tt>suspend</tt>
and <tt>resume</tt> from <b>Camel 2.11.1</b> onwards to either suspend
or resume a route. And from <b>Camel 2.11.1</b> onwards you can use <tt>stats</tt>
to get performance statics returned in XML format; the <tt>routeId</tt> option
can be used to define which route to get the performance stats for, if <tt>routeId</tt>
is not defined, then you get statistics for the entire <a href="/confluence/display/CAMEL/CamelContext"
title="CamelContext">CamelContext</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>async</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Whether to execute the control bus task asynchronously. <b>Important:</b>
If this option is enabled, then any result from the task is <b>not</b> set on
the <a href="/confluence/display/CAMEL/Exchange" title="Exchange">Exchange</a>.
This is only possible if executing tasks synchronously. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>loggingLevel</tt> </td>
<td class='confluenceTd'> <tt>INFO</tt> </td>
<td class='confluenceTd'> Logging level used for logging when task is done, or if any
exceptions occurred during processing the task. </td>
</tr>
</tbody></table>
</div>
</div>

<p>You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<h3><a name="ControlBusComponent-Samples"></a>Samples</h3>

<h4><a name="ControlBusComponent-Usingroutecommand"></a>Using route command</h4>

<p>The route command allows you to do common tasks on a given route very easily, for
example to start a route, you can send an empty message to this endpoint:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
template.sendBody(<span class="code-quote">"controlbus:route?routeId=foo&amp;action=start"</span>,
<span class="code-keyword">null</span>);
</pre>
</div></div>

<p>To get the status of the route, you can do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-object">String</span> status = template.requestBody(<span
class="code-quote">"controlbus:route?routeId=foo&amp;action=status"</span>, <span
class="code-keyword">null</span>, <span class="code-object">String</span>.class);
</pre>
</div></div>


<h5><a name="ControlBusComponent-Gettingperformancestatistics"></a>Getting
performance statistics</h5>
<p><b>Available as of Camel 2.11.1</b></p>

<p>This requires JMX to be enabled (is by default) then you can get the performance
statics per route, or for the <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a>.
For example to get the statics for a route named foo, we can do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-object">String</span> xml = template.requestBody(<span class="code-quote">"controlbus:route?routeId=foo&amp;action=stats"</span>,
<span class="code-keyword">null</span>, <span class="code-object">String</span>.class);
</pre>
</div></div>

<p>The returned statics is in XML format. Its the same data you can get from JMX with
the <tt>dumpRouteStatsAsXml</tt> operation on the <tt>ManagedRouteMBean</tt>.</p>

<p>To get statics for the entire <a href="/confluence/display/CAMEL/CamelContext"
title="CamelContext">CamelContext</a> you just omit the routeId parameter as shown
below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-object">String</span> xml = template.requestBody(<span class="code-quote">"controlbus:route?action=stats"</span>,
<span class="code-keyword">null</span>, <span class="code-object">String</span>.class);
</pre>
</div></div>


<h4><a name="ControlBusComponent-UsingSimplelanguage"></a>Using <a href="/confluence/display/CAMEL/Simple"
title="Simple">Simple</a> language</h4>

<p>You can use the <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a>
language with the control bus, for example to stop a specific route, you can send a message
to the <tt>"controlbus:language:simple"</tt> endpoint containing the following
message:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
template.sendBody(<span class="code-quote">"controlbus:language:simple"</span>,
<span class="code-quote">"${camelContext.stopRoute('myRoute')}"</span>);
</pre>
</div></div>

<p>As this is a void operation, no result is returned. However, if you want the route
status you can do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-object">String</span> status = template.requestBody(<span
class="code-quote">"controlbus:language:simple"</span>, <span class="code-quote">"${camelContext.getRouteStatus('myRoute')}"</span>,
<span class="code-object">String</span>.class);
</pre>
</div></div>

<p><b>Notice:</b> its easier to use the <tt>route</tt> command
to control lifecycle of routes. The <tt>language</tt> command allows you to execute
a language script that has stronger powers such as <a href="/confluence/display/CAMEL/Groovy"
title="Groovy">Groovy</a> or to some extend the <a href="/confluence/display/CAMEL/Simple"
title="Simple">Simple</a> language. </p>

<p>For example to shutdown Camel itself you can do:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
template.sendBody(<span class="code-quote">"controlbus:language:simple?async=<span
class="code-keyword">true</span>"</span>, <span class="code-quote">"${camelContext.stop()}"</span>);
</pre>
</div></div>
<p>Notice we use <tt>async=true</tt> to stop Camel asynchronously as otherwise
we would be trying to stop Camel while it was in-flight processing the message we sent to
the control bus component.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td>You can also use other languages
such as <a href="/confluence/display/CAMEL/Groovy" title="Groovy">Groovy</a>,
etc.</td></tr></table></div>

<h3><a name="ControlBusComponent-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring
Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting
Started</a></li>
</ul>

<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/ControlBus" title="ControlBus">ControlBus</a>
EIP</li>
	<li><a href="/confluence/display/CAMEL/JMX" title="JMX">JMX</a> Component</li>
	<li>Using <a href="/confluence/display/CAMEL/Camel+JMX" title="Camel JMX">JMX</a>
with Camel</li>
</ul>

    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/ControlBus+Component">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=30740964&revisedVersion=12&originalVersion=11">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/ControlBus+Component?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message