camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Camel > Running Camel standalone and have it keep running
Date Mon, 31 Oct 2011 07:16:00 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/2042/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="">Running
Camel standalone and have it keep running</a></h2>
    <h4>Page <b>edited</b> by             <a href="">Claus
                         <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" >The following example shows how you
can create your main class, named {{MainExample}} and use the {{Main}} class from Camel. <br>
            <tr><td class="diff-changed-lines" ><span class="diff-changed-words">{snippet:id=e1|lang=java|title=MainExample|url=camel/trunk/camel-core/src/test/java/org/apache/camel/<span
class="diff-added-chars"style="background-color: #dfd;">main/</span>}</span>
            <tr><td class="diff-unchanged" > <br>h3. Using {{camel-spring}}
JAR example <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="RunningCamelstandaloneandhaveitkeeprunning-RunningCamelstandaloneandhaveitkeeprunning"></a>Running
Camel standalone and have it keep running</h2>

<p>If you are using Camel as a standalone Java application, then Camel provides a <tt>Main</tt>
class you can reuse to more easily boot up Camel and keep it running until the JVM terminates,
for example when pressing <tt>ctrl + c</tt>.</p>

<p>The <tt>Main</tt> class is provided in the following two components</p>
<ul class="alternate" type="square">
	<li><tt>camel-core</tt> JAR in the <tt>org.apache.camel.Main</tt>
class (requires Camel 2.6)</li>
	<li><tt>camel-spring</tt> JAR in the <tt>org.apache.camel.spring.Main</tt>

<h3><a name="RunningCamelstandaloneandhaveitkeeprunning-Using%7B%7Bcamelcore%7D%7DJARexample"></a>Using
<tt>camel-core</tt> JAR example</h3>
<p><b>Available as of Camel 2.6</b></p>

<p>The following example shows how you can create your main class, named <tt>MainExample</tt>
and use the <tt>Main</tt> class from Camel.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeHeader panelHeader"
style="border-bottom-width: 1px;"><b>MainExample</b></div><div class="codeContent
<pre class="code-java"><span class="code-keyword">public</span> class MainExample

    <span class="code-keyword">private</span> Main main;

    <span class="code-keyword">public</span> <span class="code-keyword">static</span>
void main(<span class="code-object">String</span>[] args) <span class="code-keyword">throws</span>
Exception {
        MainExample example = <span class="code-keyword">new</span> MainExample();

    <span class="code-keyword">public</span> void boot() <span class="code-keyword">throws</span>
Exception {
        <span class="code-comment">// create a Main instance
</span>        main = <span class="code-keyword">new</span> Main();
        <span class="code-comment">// enable hangup support so you can press ctrl +
c to terminate the JVM
</span>        main.enableHangupSupport();
        <span class="code-comment">// add routes
</span>        main.addRouteBuilder(<span class="code-keyword">new</span>

        <span class="code-comment">// run until you terminate the JVM
</span>        <span class="code-object">System</span>.out.println(<span
class="code-quote">"Starting Camel. Use ctrl + c to terminate the JVM.\n"</span>);;

    <span class="code-keyword">private</span> <span class="code-keyword">static</span>
class MyRouteBuilder <span class="code-keyword">extends</span> RouteBuilder {
        <span class="code-keyword">public</span> void configure() <span class="code-keyword">throws</span>
Exception {
            from(<span class="code-quote">"timer:foo?delay=2000"</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-object">System</span>.out.println(<span
class="code-quote">"Invoked timer at "</span> + <span class="code-keyword">new</span>


<h3><a name="RunningCamelstandaloneandhaveitkeeprunning-Using%7B%7Bcamelspring%7D%7DJARexample"></a>Using
<tt>camel-spring</tt> JAR example</h3>

<p>This would be similar to the <tt>camel-core</tt> JAR example, however
you would use the <tt>Main</tt> class from the <tt>org.apache.camel.spring</tt>
The <tt>Main</tt> class from <tt>camel-spring</tt> JAR has many more
options and is prepared for booting Camel from Spring XML files.</p>

<h3><a name="RunningCamelstandaloneandhaveitkeeprunning-SeeAlso"></a>See
<ul class="alternate" type="square">
	<li><a href="/confluence/display/CAMEL/Running+Camel+standalone" title="Running
Camel standalone">Running Camel standalone</a></li>
	<li>Chapter 13 in the <a href="/confluence/display/CAMEL/Books" title="Books">Camel
in Action book</a> explains more about running Camel</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="">View
        <a href=";showCommentArea=true#addcomment">Add

View raw message