camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Lifecycle
Date Sun, 01 Aug 2010 10:05:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/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/Lifecycle">Lifecycle</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (1)</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" > <br>If you are working with
Spring you may wish to read the [Camel Spring documentation|Spring]. <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
<br>h3. CamelContext Lifecycle <br> <br>The {{CamelContext}} provides methods
to control its lifecycle: <br>- {{start}} <br>- {{stop}} <br>- {{suspend}}
*Camel 2.5* <br>- {{resume}} *Camel 2.5* <br> <br>The operations is paired:
start/stop and suspend/resume. <br> <br>Stop is performing a [Graceful shutdown]
which means all its internal state, cache, etc is cleared. And the routes is being stopped
in a graceful manner to ensure messages is given time to complete. If you start a {{CamelContext}}
after a stop, then its performing a _cold_ start, recreating all the state, cache etc. again.
 <br> <br>Instead you can use the suspend/resume operations. They will keep the
{{CamelContext}} _warm_ and only suspend/stop routes using the same [Graceful shutdown] feature.
This ensures messages is given time to complete. <br> <br>End users is encouraged
to use suspend/resume if you are temporary stopping a Camel application. <br> <br>All
these operations is available in [JMX|Camel JMX] as well, so you can control Camel from a
management console. <br> <br>{tip:unit testing restart} <br>If you write
unit tests and perform _cold_ restarts using stop/start then any previously looked up [Endpoint]s
etc. is obsolete, and therefore you need to re-lookup those endpoints again. <br> <br>Instead
use suspend/resume which keeps these [Endpoint]s and therefore you can still use them after
resuming. <br>{tip} <br> <br>h3. Service lifecycle <br> <br>A
service in Camel adheres to the following lifecycle states as illustrated in the diagram below:
<br> <br>!service_lifecycle.png! <br> <br>*Notice:* A service can
optimally support suspend/resume by the {{SuspendableService}}. This means not all services
in Camel supports suspension. It&#39;s encouraged that consumers support suspension which
allows to suspend/resume routes. <br> <br>h3. Routes lifecycle <br> <br>Routes
in Camel have the following operations to control its lifecycle <br> <br>- {{start}}
<br>- {{stop}} <br>- {{suspend}} <br>- {{resume}} <br>- {{shutdown}}
<br> <br>The {{shutdown}} operation will also *remove* the route, for example
in [JMX|Camel JMX] the route will then be unregistered and its gone. So only use shutdown
if you really want to remove the route. <br> <br>If a route consumer does not
support suspension, it will fallback and stop the route instead. <br> <br>h3.
See Also <br>- [CamelContext] <br>- [Architecture] <br>- [JMX|Camel JMX]
<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Lifecycle-CamelLifecycle"></a>Camel Lifecycle</h2>

<p>Camel uses a simple <em>lifecycle</em> interface called <a href="http://activemq.apache.org/camel/maven/camel-core/apidocs/org/apache/camel/Service.html"
class="external-link" rel="nofollow">Service</a> which has a single start() and stop()
method.</p>

<p>Various classes implement Service such as <a href="/confluence/display/CAMEL/CamelContext"
title="CamelContext">CamelContext</a> along with a number of <a href="/confluence/display/CAMEL/Component"
title="Component">Component</a> and <a href="/confluence/display/CAMEL/Endpoint"
title="Endpoint">Endpoint</a> classes.</p>

<p>When you use Camel you typically have to start the <a href="/confluence/display/CAMEL/CamelContext"
title="CamelContext">CamelContext</a> which will start all the various components
and endpoints and activate the routing rules until the context is stopped again.</p>

<p>If you are working with Spring you may wish to read the <a href="/confluence/display/CAMEL/Spring"
title="Spring">Camel Spring documentation</a>.</p>

<h3><a name="Lifecycle-CamelContextLifecycle"></a>CamelContext Lifecycle</h3>

<p>The <tt>CamelContext</tt> provides methods to control its lifecycle:</p>
<ul class="alternate" type="square">
	<li><tt>start</tt></li>
	<li><tt>stop</tt></li>
	<li><tt>suspend</tt> <b>Camel 2.5</b></li>
	<li><tt>resume</tt> <b>Camel 2.5</b></li>
</ul>


<p>The operations is paired: start/stop and suspend/resume.</p>

<p>Stop is performing a <a href="/confluence/display/CAMEL/Graceful+Shutdown" title="Graceful
Shutdown">Graceful Shutdown</a> which means all its internal state, cache, etc is
cleared. And the routes is being stopped in a graceful manner to ensure messages is given
time to complete. If you start a <tt>CamelContext</tt> after a stop, then its
performing a <em>cold</em> start, recreating all the state, cache etc. again.
</p>

<p>Instead you can use the suspend/resume operations. They will keep the <tt>CamelContext</tt>
<em>warm</em> and only suspend/stop routes using the same <a href="/confluence/display/CAMEL/Graceful+Shutdown"
title="Graceful Shutdown">Graceful Shutdown</a> feature. This ensures messages is
given time to complete.</p>

<p>End users is encouraged to use suspend/resume if you are temporary stopping a Camel
application.</p>

<p>All these operations is available in <a href="/confluence/display/CAMEL/Camel+JMX"
title="Camel JMX">JMX</a> as well, so you can control Camel from a management console.</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>If you write unit tests and perform
<em>cold</em> restarts using stop/start then any previously looked up <a href="/confluence/display/CAMEL/Endpoint"
title="Endpoint">Endpoint</a>s etc. is obsolete, and therefore you need to re-lookup
those endpoints again.

<p>Instead use suspend/resume which keeps these <a href="/confluence/display/CAMEL/Endpoint"
title="Endpoint">Endpoint</a>s and therefore you can still use them after resuming.</p></td></tr></table></div>

<h3><a name="Lifecycle-Servicelifecycle"></a>Service lifecycle</h3>

<p>A service in Camel adheres to the following lifecycle states as illustrated in the
diagram below:</p>

<p><span class="error">Unable to render embedded object: File (service_lifecycle.png)
not found.</span></p>

<p><b>Notice:</b> A service can optimally support suspend/resume by the
<tt>SuspendableService</tt>. This means not all services in Camel supports suspension.
It's encouraged that consumers support suspension which allows to suspend/resume routes.</p>

<h3><a name="Lifecycle-Routeslifecycle"></a>Routes lifecycle</h3>

<p>Routes in Camel have the following operations to control its lifecycle</p>

<ul class="alternate" type="square">
	<li><tt>start</tt></li>
	<li><tt>stop</tt></li>
	<li><tt>suspend</tt></li>
	<li><tt>resume</tt></li>
	<li><tt>shutdown</tt></li>
</ul>


<p>The <tt>shutdown</tt> operation will also <b>remove</b> the
route, for example in <a href="/confluence/display/CAMEL/Camel+JMX" title="Camel JMX">JMX</a>
the route will then be unregistered and its gone. So only use shutdown if you really want
to remove the route.</p>

<p>If a route consumer does not support suspension, it will fallback and stop the route
instead.</p>

<h3><a name="Lifecycle-SeeAlso"></a>See Also</h3>
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/CamelContext" title="CamelContext">CamelContext</a></li>
	<li><a href="/confluence/display/CAMEL/Architecture" title="Architecture">Architecture</a></li>
	<li><a href="/confluence/display/CAMEL/Camel+JMX" title="Camel JMX">JMX</a></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/Lifecycle">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=52927&revisedVersion=2&originalVersion=1">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Lifecycle?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message