camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Camel > How can I stop a route from a route
Date Sun, 03 Oct 2010 06:45:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/1810/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
<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="">How
can I stop a route from a route</a></h2>
    <h4>Page  <b>added</b> by             <a href="">Claus
    <div class="notificationGreySide">
         <h2><a name="HowcanIstoparoutefromaroute-HowcanIstoparoutefromaroute"></a>How
can I stop a route from a route</h2>

<p>The <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a>
provides API for managing routes at runtime. It has a <tt>stopRoute(id)</tt> and
<tt>startRoute(id)</tt> methods.</p>

<p>Stopping a route during routing an existing message is a bit tricky. The reason for
that is Camel will graceful shutdown the route you are stopping. And if you do that while
a message is being routed the graceful shutdown will try to wait until that message has been
Now that message can easily be yourself. So to cater for that you have to tell Camel that
you are done routing this message which you do by removing it from the in flight registry.
The follow code shows how you can stop a route from a <a href="/confluence/display/CAMEL/Processor"

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"direct:start"</span>)
    .to(<span class="code-quote">"bean:foo?method=doSomething"</span>).routeId(<span
    .process(<span class="code-keyword">new</span> Processor() { 
        <span class="code-keyword">public</span> void process(Exchange exchange)
<span class="code-keyword">throws</span> Exception {
            <span class="code-comment">// remove myself from the in flight registry
so we can stop <span class="code-keyword">this</span> route without trouble
</span>            context.getInflightRepository().remove(exchange);
            <span class="code-comment">// stop <span class="code-keyword">this</span>
</span>            context.stopRoute(<span class="code-quote">"myCoolRoute"</span>);

<p>Camel provides another feature for managing routes at runtime which is <a href="/confluence/display/CAMEL/RoutePolicy"

<p>And <a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a>
also provides API for suspend/resume of routes, and shutdown as well.</p>
<ul class="alternate" type="square">
	<li>suspend/resume is faster than stop/start. For example a HTTP server will still
run but deny any incoming requests.<br/>
  Where as if it was stopped the HTTP listener would have been stopped.</li>
	<li>shutdown means the route is being removed from <a href="/confluence/display/CAMEL/CamelContext"
title="CamelContext">CamelContext</a> and cannot be started again. Its also removed
from JMX.</li>

<h3><a name="HowcanIstoparoutefromaroute-SeeAlso"></a>See Also</h3>
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/RoutePolicy" title="RoutePolicy">RoutePolicy</a></li>

    <div id="commentsSection" class="wiki-content pageSection">
       <div style="float: right;">
            <a href=""
class="grey">Change Notification Preferences</a>
       <a href="">View
       <a href=";showCommentArea=true#addcomment">Add

View raw message