camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Running Camel standalone and have it keep running
Date Mon, 31 Oct 2011 07:16: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/Running+Camel+standalone+and+have+it+keep+running">Running
Camel standalone and have it keep running</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" >The following example shows how you
can create your main class, named {{MainExample}} and use the {{Main}} class from Camel. <br>
<br></td></tr>
            <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>MainExample.java}</span>
<br></td></tr>
            <tr><td class="diff-unchanged" > <br>h3. Using {{camel-spring}}
JAR example <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </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>
class</li>
</ul>


<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
panelContent">
<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();
        example.boot();
    }

    <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>
MyRouteBuilder());

        <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>);
        main.run();
    }

    <span class="code-keyword">private</span> <span class="code-keyword">static</span>
class MyRouteBuilder <span class="code-keyword">extends</span> RouteBuilder {
        @Override
        <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>
Date());
                    }
                });
        }
    }

}
</pre>
</div></div>

<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>
package.<br/>
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
Also</h3>
<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>
</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/Running+Camel+standalone+and+have+it+keep+running">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=24192769&revisedVersion=4&originalVersion=3">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Running+Camel+standalone+and+have+it+keep+running?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message