Author: buildbot Date: Thu Nov 27 22:18:51 2014 New Revision: 930815 Log: Production update by buildbot for camel
Modified: websites/production/camel/content/cache/main.pageCache websites/production/camel/content/camel-and-scr.html Modified: websites/production/camel/content/cache/main.pageCache ============================================================================== Binary files - no diff available. Modified: websites/production/camel/content/camel-and-scr.html ============================================================================== --- websites/production/camel/content/camel-and-scr.html (original) +++ websites/production/camel/content/camel-and-scr.html Thu Nov 27 22:18:51 2014 @@ -92,7 +92,7 @@ cardinality = ReferenceCardinality.MANDATORY_MULTIPLE, policy = ReferencePolicy.DYNAMIC, policyOption = ReferencePolicyOption.GREEDY, bind = "gotCamelComponent", unbind = "lostCamelComponent") })]]></script> -</div></div><p> </p><p>Then implement <code>getRouteBuilders()</code> method which returns the Camel routes you want to run:</p><p> </p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Load routes</b></div><div class="codeContent panelContent pdl"> +</div></div><p> </p><p>Then implement <code>getRouteBuilders()</code> method which returns the Camel routes you want to run:</p><p> </p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Implement getRouteBuilders()</b></div><div class="codeContent panelContent pdl"> <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ @Override protected List<RoutesBuilder> getRouteBuilders() { List<RoutesBuilder> routesBuilders = new ArrayList<>(); @@ -100,7 +100,7 @@ routesBuilders.add(new AnotherRouteBuilderHere(registry)); return routesBuilders; }]]></script> -</div></div><p> </p><p>And finally provide the default configuration with:</p><p> </p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Define configuration with annotations</b></div><div class="codeContent panelContent pdl"> +</div></div><p> </p><p>And finally provide the default configuration with:</p><p> </p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Default configuration in annotations</b></div><div class="codeContent panelContent pdl"> <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[@Properties({ @Property(name = "camelContextId", value = "my-test"), @Property(name = "active", value = "true"), @@ -219,7 +219,7 @@ public class CamelScrExampleRoute extend Validate.notNull(maximumRedeliveryDelay, "maximumRedeliveryDelay property is not set"); } }]]></script> -</div></div><p> </p><p>Let's take a look at CamelScrExampleRoute in more detail.</p><p> </p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +</div></div><p> </p><p>Let's take a look at <code>CamelScrExampleRoute</code> in more detail.</p><p> </p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ // Configured fields private String camelRouteId; private Integer maximumRedeliveries; @@ -257,7 +257,7 @@ public class CamelScrExampleRoute extend .otherwise() .log(LoggingLevel.ERROR, "{{messageError}}") .end();]]></script> -</div></div><p>Note that pretty much everything in the route is configured with properties. This essentially makes your RouteBuilder a template. SCR allows you to create more instances of your routes just by providing alternative configurations. More on this in section <em>Using Camel SCR bundle as a template</em>.</p><h4 id="CamelandSCR-AbstractCamelRunner'slifecycleinSCR">AbstractCamelRunner's lifecycle in SCR</h4><ol><li>When component's configuration policy and mandatory references are satisfied SCR calls <code>activate()</code>. This creates and sets up a CamelContext through the following call chain: <code>activate()</code> → <code>prepare()</code> → <code>createCamelContext()</code> → <code>setupPropertiesComponent()</code> → <code>configure()</code> → <code>setupCamelContext()</code>. Finally, the context is scheduled to start after a delay defined in <code>AbstractCamelRunner.START_DELAY</code> with <code >runWithDelay()</code>.</li><li><span style="line-height: 1.4285715;">When >Camel components (<code>ComponentResolver</code> services, to be exact) are >registered in OSGi, SCR calls </span><code>gotCamelComponent</code><span >style="line-height: 1.4285715;"><code>()</code> which reschedules/delays the >CamelContext start further by the same ></span><code>AbstractCamelRunner.START_DELAY</code><span style="line-height: >1.4285715;">. This in effect makes CamelContext wait until all Camel >components are loaded or there is a sufficient gap between them. The same >logic will tell a failed-to-start CamelContext to try again whenever we add >more Camel components.</span></li><li><span style="line-height: >1.4285715;">When Camel components are unregistered SCR calls ></span><code>lostCamelComponent</code><span style="line-height: >1.4285715;"><code>()</code>. This call does nothing.</span></li><li><span >style="line-height: 1.4285715;">When one of the requirements that caused the >call to </span><code> activate</code><span style="line-height: 1.4285715;"><code>()</code> is lost SCR will call </span><code>deactivate</code><span style="line-height: 1.4285715;"><code>()</code>. This will shutdown the CamelContext.</span></li></ol><p>In (non-OSGi) unit tests you should use <code>prepare()</code> → <code>run()</code> → <code>stop()</code> instead of <code>activate()</code> → <code>deactivate()</code> for more fine-grained control. Also, this allows us to avoid possible SCR specific operations in tests.</p><h3 id="CamelandSCR-Usingcamel-archetype-scr">Using camel-archetype-scr</h3><p>The easiest way to create an Camel SCR bundle project is to use <code>camel-archetype-scr</code> and Maven.</p><p>You can generate a project with the following steps:</p><p> </p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Generating a project</b></div><div class="codeContent pan elContent pdl"> +</div></div><p>Note that pretty much everything in the route is configured with properties. This essentially makes your RouteBuilder a template. SCR allows you to create more instances of your routes just by providing alternative configurations. More on this in section <em>Using Camel SCR bundle as a template</em>.</p><h4 id="CamelandSCR-AbstractCamelRunner'slifecycleinSCR">AbstractCamelRunner's lifecycle in SCR</h4><ol><li>When component's configuration policy and mandatory references are satisfied SCR calls <code>activate()</code>. This creates and sets up a CamelContext through the following call chain: <code>activate()</code> → <code>prepare()</code> → <code>createCamelContext()</code> → <code>setupPropertiesComponent()</code> → <code>configure()</code> → <code>setupCamelContext()</code>. Finally, the context is scheduled to start after a delay defined in <code>AbstractCamelRunner.START_DELAY</code> with <code >runWithDelay()</code>.</li><li><span style="line-height: 1.4285715;">When >Camel components (<code>ComponentResolver</code> services, to be exact) are >registered in OSGi, SCR calls </span><code>gotCamelComponent</code><span >style="line-height: 1.4285715;"><code>()</code> which reschedules/delays the >CamelContext start further by the same ></span><code>AbstractCamelRunner.START_DELAY</code><span style="line-height: >1.4285715;">. This in effect makes CamelContext wait until all Camel >components are loaded or there is a sufficient gap between them. The same >logic will tell a failed-to-start CamelContext to try again whenever we add >more Camel components.</span></li><li><span style="line-height: >1.4285715;">When Camel components are unregistered SCR calls ></span><code>lostCamelComponent</code><span style="line-height: >1.4285715;"><code>()</code>. This call does nothing.</span></li><li><span >style="line-height: 1.4285715;">When one of the requirements that caused the >call to </span><code> activate</code><span style="line-height: 1.4285715;"><code>()</code> is lost SCR will call </span><code>deactivate</code><span style="line-height: 1.4285715;"><code>()</code>. This will shutdown the CamelContext.</span></li></ol><p>In (non-OSGi) unit tests you should use <code>prepare()</code> → <code>run()</code> → <code>stop()</code> instead of <code>activate()</code> → <code>deactivate()</code> for more fine-grained control. Also, this allows us to avoid possible SCR specific operations in tests.</p><h3 id="CamelandSCR-Usingcamel-archetype-scr">Using camel-archetype-scr</h3><p>The easiest way to create an Camel SCR bundle project is to use <code>camel-archetype-scr</code> and Maven.</p><p>You can generate a project with the following steps:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Generating a project</b></div><div class="codeContent panelContent pdl "> <script class="theme: Default; brush: text; gutter: false" type="syntaxhighlighter"><![CDATA[$ mvn archetype:generate -Dfilter=org.apache.camel.archetypes:camel-archetype-scr  Choose archetype: @@ -282,39 +282,9 @@ archetypeGroupId: org.apache.camel.arche archetypeVersion: 2.15-SNAPSHOT className: CamelScrExample Y: :]]></script> -</div></div><p> </p><p>All done! See ReadMe.txt in the generated project folder for the next steps:</p><p> </p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>ReadMe.txt</b></div><div class="codeContent panelContent pdl"> -<script class="theme: Default; brush: text; gutter: false" type="syntaxhighlighter"><![CDATA[Camel SCR bundle project -======================== - -To build this project run - - mvn install - -To deploy this project in Apache Karaf (2.4.0) - - On Karaf command line: - - # Add Camel feature repository - features:chooseurl camel 2.15-SNAPSHOT - - # Install camel-scr feature - features:install camel-scr - - # Install commons-lang, used in the example route to validate parameters - osgi:install mvn:commons-lang/commons-lang/2.6 - - # Install and start your bundle - osgi:install -s mvn:example/camel-scr-example/1.0-SNAPSHOT - - # See how it's running - log:tail -n 10 - - Press ctrl-c to stop watching the log. - -For more help see the Apache Camel documentation - - http://camel.apache.org/]]></script> -</div></div><h3 id="CamelandSCR-UnittestingCamelroutes">Unit testing Camel routes</h3><p>Service Component is a POJO and has no special requirements for (non-OSGi) unit testing. There are however some techniques that are specific to Camel SCR or just make testing easier.</p><p><span style="line-height: 1.4285715;">Below is an example unit test, generated by </span><code style="line-height: 1.4285715;">camel-archetype-scr</code><span style="line-height: 1.4285715;">:</span></p><p><span style="line-height: 1.4285715;"><br clear="none"></span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>CamelScrExampleTest.java</b></div><div class="codeContent panelContent pdl"> +</div></div><p><span style="font-size: 14.0px;line-height: 1.4285715;">Done!</span></p><p><span style="font-size: 14.0px;line-height: 1.4285715;">Now run:</span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[mvn install]]></script> +</div></div><p>and the bundle is ready to be deployed.</p><h3 id="CamelandSCR-UnittestingCamelroutes">Unit testing Camel routes</h3><p>Service Component is a POJO and has no special requirements for (non-OSGi) unit testing. There are however some techniques that are specific to Camel SCR or just make testing easier.</p><p><span style="line-height: 1.4285715;">Below is an example unit test, generated by </span><code style="line-height: 1.4285715;">camel-archetype-scr</code><span style="line-height: 1.4285715;">:</span></p><p><span style="line-height: 1.4285715;"><br clear="none"></span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>CamelScrExampleTest.java</b></div><div class="codeContent panelContent pdl"> <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[// This file was generated from org.apache.camel.archetypes/camel-archetype-scr/2.15-SNAPSHOT package example; @@ -428,7 +398,42 @@ public class CamelScrExampleTest { </div></div><p>Here we start the Service Component and along with it the routes.</p><p> </p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Sending a test message</b></div><div class="codeContent panelContent pdl"> <script class="theme: Default; brush: java; gutter: false" type="syntaxhighlighter"><![CDATA[ // Send the test message context.createProducerTemplate().sendBody("direct:start", "hello");]]></script> -</div></div><p>Here we send a message to a route in test.</p><h3 id="CamelandSCR-UsingCamelSCRbundleasatemplate">Using Camel SCR bundle as a template</h3><p>TODO</p></div> +</div></div><p>Here we send a message to a route in test.</p><h3 id="CamelandSCR-RunningthebundleinApacheKaraf">Running the bundle in Apache Karaf</h3><p>Once the bundle has been built with <code>mvn install</code> it's ready to be deployed. <span style="font-size: 14.0px;line-height: 1.4285715;">To deploy the project in Apache Karaf perform the following steps on Karaf command line:</span></p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Deploying the bundle in Apache Karaf</b></div><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: text; gutter: false" type="syntaxhighlighter"><![CDATA[# Add Camel feature repository +karaf@root> features:chooseurl camel 2.15-SNAPSHOT + +# Install camel-scr feature +karaf@root> features:install camel-scr + +# Install commons-lang, used in the example route to validate parameters +karaf@root> osgi:install mvn:commons-lang/commons-lang/2.6 + +# Install and start your bundle +karaf@root> osgi:install -s mvn:example/camel-scr-example/1.0-SNAPSHOT + +# See how it's running +karaf@root> log:tail -n 10 + +Press ctrl-c to stop watching the log.]]></script> +</div></div><h4 id="CamelandSCR-Overridingthedefaultconfiguration"><span style="font-size: 14.0px;line-height: 1.4285715;">Overriding the default configuration</span></h4><p>By default, Service Component's configuration PID equals the fully qualified name of its class. You can change the example bundle's properties with Karaf's <code>config:*</code> commands:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Override a property</b></div><div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: text; gutter: false" type="syntaxhighlighter"><![CDATA[# Override 'messageOk' property +karaf@root> config:propset -p example.CamelScrExample messageOk "This is better logging"]]></script> +</div></div><p>Or you can change the configuration directly by editing property files in Karaf's <code>etc</code> folder.</p><h4 id="CamelandSCR-UsingCamelSCRbundleasatemplate"><span style="font-size: 16.0px;line-height: 1.5625;">Using Camel SCR bundle as a template</span></h4><p>Let's say you have a Camel SCR bundle that implements an integration pattern that you use frequently, say, <strong>from → to</strong>, with success/failure logging and redelivery which also happens to be the pattern our example route implements. You probably don't want to create a separate bundle for every instance. No worries, SCR has you covered.</p><p>Create a configuration PID for your Service Component, but add a tail with a dash and SCR will use that configuration to create a new instance of your component.</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Creating a new Service Component instance</b></div> <div class="codeContent panelContent pdl"> +<script class="theme: Default; brush: text; gutter: false" type="syntaxhighlighter"><![CDATA[# Create a PID with a tail +karaf@root> config:edit example.CamelScrExample-anotherone + +# Override some properties +karaf@root> config:propset camelContextId my-other-context +karaf@root> config:propset to "file://removeme?fileName=removemetoo.txt" + +# Save the PID +karaf@root> config:update]]></script> +</div></div><p>This will start a new CamelContext with your overridden properties. How convenient.</p> <div class="aui-message success shadowed information-macro"> + <span class="aui-icon icon-success">Icon</span> + <div class="message-content"> + <p>When designing a Service Component to be a template you typically don't want it to start without a "tailed" configuration i.e. with the default configuration.</p><p>To prevent your Service Component from starting with the default configuration add <code><span style="font-size: 14.0px;line-height: 1.4285715;">policy = ConfigurationPolicy.</span><span style="font-size: 14.0px;line-height: 1.4285715;">REQUIRE </span></code><span style="font-family: Arial , sans-serif;font-size: 14.0px;line-height: 1.4285715;">to the class level </span><code style="font-size: 14.0px;line-height: 1.4285715;">@Component</code><span style="font-family: Arial , sans-serif;font-size: 14.0px;line-height: 1.4285715;"> annotation.</span></p> + </div> + </div></div> </td> <td valign="top"> <div class="navigation">