servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache ServiceMix > Basic
Date Wed, 22 Sep 2010 11:37:01 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/1810/9/13/_/styles/combined.css?spaceKey=SM&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/SM/Basic">Basic</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" >h2. Overview <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >This document describes how to
run the _Basic_ example and provides details about what it does. For information on the business
use case, please refer to: [Use Case for <span class="diff-deleted-words"style="color:#999;background-color:#fdd;text-decoration:line-through;">Basic|http://www.servicemix.org/Use+Cases].</span>
<span class="diff-added-words"style="background-color: #dfd;">Basic|Use Cases (whole)].</span>
<br></td></tr>
            <tr><td class="diff-unchanged" >\\ <br>\\ <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
        </table>
</div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <style type='text/css'>/*<![CDATA[*/
table.ScrollbarTable  {border: none;padding: 3px;width: 100%;padding: 3px;margin: 0px;background-color:
#f0f0f0}
table.ScrollbarTable td.ScrollbarPrevIcon {text-align: center;width: 16px;border: none;}
table.ScrollbarTable td.ScrollbarPrevName {text-align: left;border: none;}
table.ScrollbarTable td.ScrollbarParent {text-align: center;border: none;}
table.ScrollbarTable td.ScrollbarNextName {text-align: right;border: none;}
table.ScrollbarTable td.ScrollbarNextIcon {text-align: center;width: 16px;border: none;}

/*]]>*/</style><div class="Scrollbar"><table class='ScrollbarTable'><tr><td
width='33%' class='ScrollbarPrevName'>&nbsp;</td><td width='33%' class='ScrollbarParent'><sup><a
href="/confluence/display/SM/4.+Examples"><img border='0' align='middle' src='/confluence/images/icons/up_16.gif'
width='8' height='8'></a></sup><a href="/confluence/display/SM/4.+Examples">4.
Examples</a></td><td width='33%' class='ScrollbarNextName'>&nbsp;<a
href="/confluence/display/SM/Bridge">Bridge</a></td><td class='ScrollbarNextIcon'><a
href="/confluence/display/SM/Bridge"><img border='0' align='middle' src='/confluence/images/icons/forwd_16.gif'
width='16' height='16'></a></td></tr></table></div>
<p><a name="Basic-top"></a></p>

<h1><a name="Basic-BasicExample"></a>Basic Example</h1>


<h2><a name="Basic-Overview"></a>Overview</h2>

<p>This document describes how to run the <em>Basic</em> example and provides
details about what it does. For information on the business use case, please refer to: <a
href="/confluence/display/SM/Use+Cases+%28whole%29" title="Use Cases (whole)">Use Case
for Basic</a>.
<br class="atl-forced-newline" />
<br class="atl-forced-newline" />
The Basic example illustrates the following:</p>
<ul>
	<li>use of declarative programming</li>
	<li>how to use an <a href="http://activemq.apache.org/spring-support.html" class="external-link"
rel="nofollow">ActiveMQ</a> message broker</li>
	<li>how to use a <a href="http://incubator.apache.org/servicemix/servicemix-quartz.html"
class="external-link" rel="nofollow">Quartz</a> timer</li>
	<li>how to use the <a href="http://jencks.org/" class="external-link" rel="nofollow">Jencks</a>
JCA container</li>
	<li>how to use the <a href="http://geronimo.apache.org/" class="external-link" rel="nofollow">Geronimo</a>
Transaction Manager via the <a href="http://jencks.org/Transaction+Manager" class="external-link"
rel="nofollow">Jencks factory bean</a></li>
	<li>how to use tracing</li>
</ul>


<p>The source code for the Basic example is located in the ServiceMix installation directory
under the <tt>examples\basic\src\main\resources</tt> directory in the <tt>servicemix.xml</tt>
file. It is recommended that you refer to the source code while reading this document.
<br class="atl-forced-newline" />
<br class="atl-forced-newline" />
There are several components in the <tt>servicemix.xml</tt>file. One component
sets off a trigger to send messages to a source destination. Then those messages are consumed
by another component and sent to a different output destination. A trace component displays
the messages as they arrive.
<br class="atl-forced-newline" />
<br class="atl-forced-newline" /></p>

<h2><a name="Basic-RunningtheBasicExample"></a>Running the <em>Basic</em>
Example</h2>

<p>From a command shell, go to the Basic example directory:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
cd [servicemix_install_dir]\examples\basic
</pre>
</div></div>
<p><br class="atl-forced-newline" />
Then type:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
mvn jbi:embeddedServicemix
</pre>
</div></div>
<p><br class="atl-forced-newline" />
<br class="atl-forced-newline" /></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><b>Handy Hint</b><br
/>This example starts an ActiveMQ JMS Broker, so be sure to stop any ServiceMix server
already running.</td></tr></table></div>

<h2><a name="Basic-StoppingtheBasicExample"></a>Stopping the <em>Basic</em>
Example</h2>

<p>To terminate the Basic example type "CTRL-C" in the command shell in which it is
running.
<br class="atl-forced-newline" /></p>

<h2><a name="Basic-HowitWorks"></a>How it Works</h2>

<p>The diagram below illustrates the flow of messages through the <em>Basic</em>
components.
<br class="atl-forced-newline" />
<br class="atl-forced-newline" /></p>
<div class="panel" style="border-color: #ccc;border-style: solid;border-width: 1px;"><div
class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color:
#ccc;"><b>Basic Example Message Flow Diagram</b></div><div class="panelContent">
<p><span class="image-wrap" style="display: block; text-align: center"><img
src="/confluence/download/attachments/38885/basicflow1.jpg?version=1&amp;modificationDate=1157535011000"
style="border: 0px solid black" /></span><br/>
&nbsp;</p>
</div></div>
<p><br class="atl-forced-newline" />
<br class="atl-forced-newline" /></p>

<p>Messages flow through the components as follows:</p>
<ol>
	<li>The <em>timer</em> component sends a message to <em>inputSender</em>
through the Normalized Message Router (NMR).</li>
	<li><em>inputSender</em> converts the message (marshals it) into a JMS
message, then uses the <em>jmsTemplate</em> bean to publish the message.</li>
	<li><em>jmsTemplate</em> uses the <em>jmsFactory</em>bean to
get a connection to the port associated with the JMS topic called "demo.org.servicemix.source."
The message is published on the "demo.org.servicemix.source" topic.</li>
	<li><em>jencks</em> (the JCA resource adapter) listens on port 61616 for
messages.</li>
	<li><em>inputReceiver</em> subscribes to the "demo.org.servicemix.source"
topic via <em>jencks</em> and receives the JMS message.</li>
	<li><em>inputReceiver</em> normalizes the JMS message and sends it to <em>outputSender</em>
via the NMR.</li>
	<li><em>outputSender</em> marshals the normalized message to a JMS message
and uses <em>jmsTemplate</em> to publish the message on the "demo.org.servicemix.result"
topic.</li>
	<li><em>jmsTemplate</em> publishes it on the "demo.org.servicemix.result"
topic using <em>jmsFactory</em> to get a connection to the result topic.</li>
	<li><em>jencks</em> listens on port 61616 for messages.</li>
	<li><em>jmsTrace</em> subscribes to the "demo.org.servicemix.result" topic
and receives the JMS message via <em>jencks</em>.</li>
	<li><em>jmsTrace</em> converts the JMS message into a normalized message
and sends it to <em>trace</em> via the NMR.</li>
	<li><em>trace</em> transforms the normalized message into a string and
logs it to the console.
<br class="atl-forced-newline" /></li>
</ol>


<p>Every 5 seconds logging information is written to the console, followed by information
from the trace component. Note, that the triggers' property values of "name", "My Example
Job", "group", and "ServiceMix" are displayed along with a timestamp. Typical output looks
like the following:
<br class="atl-forced-newline" /></p>
<div class="preformatted panel" style="border-width: 1px;"><div class="preformattedContent
panelContent">
<pre>INFO  TraceComponent - Exchange: InOnly[
  id: ID:guillaumes-1927-1157464363171-19:11
  status: Active
  role: provider
  service: {http://servicemix.apache.org/demo/}trace
  endpoint: trace
  in: &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;timer&gt;
        &lt;name&gt;My Example Job&lt;/name&gt;
        &lt;group&gt;ServiceMix&lt;/group&gt;
        &lt;fullname&gt;ServiceMix.My Example Job&lt;/fullname&gt;
        &lt;description/&gt;
        &lt;fireTime&gt;Tue Sep 05 15:53:39 CEST 2006&lt;/fireTime&gt;
      &lt;/timer&gt;
</pre>
</div></div>

<h2><a name="Basic-Details"></a>Details</h2>

<p>The following table provides more details about the function of each component and
bean in the servicemix.xml file.
<br class="atl-forced-newline" />
<br class="atl-forced-newline" /></p>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Component or Bean ID </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <em>jbi</em> </td>
<td class='confluenceTd'> <em>jbi</em> is the "id" of the JBI container
and provides the basic infrastructure services for the following components: <em>timer</em>,
<em>inputSender</em>, <em>inputReceiver</em>, <em>outputSender</em>,
<em>jmsTrace</em>, and <em>trace</em>.  During initialization, several
singletons are instantiated: <em>transactionManager</em>, <em>broker</em>,
<em>jencks</em>, <em>jmsFactory</em>, and <em>jbi</em>.
After initialization, the components in the <em>jbi</em> container are activated,
starting with the <em>timer</em> component. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>timer</em> </td>
<td class='confluenceTd'> The <em>timer</em> component shows the use of
the QuartzComponent class. Every 5 seconds, until the program is terminated, the timer component
kicks off an instance of a SimpleTrigger, which is associated with an instance of JobDetail.
The job has a property called "name" with a value of "My Example Job" and another property
called "group" with a value of "ServiceMix." The resulting message is converted to a normalized
message and routed through the NMR. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>inputSender</em> </td>
<td class='confluenceTd'> This is a component inside the JBI container. It receives
the normalized message (the message from the trigger), converts it to a JMS message, and publishes
it to the topic called demo.org.servicemix.source. It uses the <em>jmsTemplate</em>(1)
bean to handle the publish. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>inputReceiver</em> </td>
<td class='confluenceTd'> This component uses <em>jencks</em> , the JCA
container, to listen on port 61616 for a JMS message on the topic called "demo.org.servicemix.source."
<em>inputReceiver</em> subscribes to the demo.org.servicemix.source topic. It
takes the message, normalizes it, and routes it to <em>outputSender</em> via the
NMR. This component combined with <em>outputSender</em> and supporting beans creates
a JMS bridge between two topics. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>outputSender</em> </td>
<td class='confluenceTd'> This component receives a normalized message from the NMR,
marshals it into a JMS message using <em>jmsTemplate</em>, then publishes it on
the ActiveMQ (JMS) topic called "demo.org.servicemix.result." </td>
</tr>
<tr>
<td class='confluenceTd'> <em>jmsTrace</em> </td>
<td class='confluenceTd'> This component uses <em>jencks</em> to subscribe
to the "demo.org.servicemix.result" topic and get messages. It then marshals the message into
a normalized message and routes it via the NMR to the <em>trace</em> component.
</td>
</tr>
<tr>
<td class='confluenceTd'> <em>trace</em> </td>
<td class='confluenceTd'> Receives normalized messages from <em>jmsTrace</em>
via the NMR. It transforms the normalized message into a string and logs it to the console.
</td>
</tr>
<tr>
<td class='confluenceTd'> <em>jencks</em> </td>
<td class='confluenceTd'> The <em>jencks</em> bean defines a JCA container.
The JCA container allows you to configure thread pool size, configure a transaction manager,
and configure a resource adapter. In this example, the resource adapter is an ActiveMQ adapter,
however, another JMS listener could be configured instead. This adapter listens on port 61616
for JMS messages. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>broker</em> </td>
<td class='confluenceTd'> The <em>broker</em> bean uses the <tt>activemq.xml</tt>
file to configure the message broker, which handles the JMS messages for the components that
require JMS messaging services. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>transactionManager</em> </td>
<td class='confluenceTd'> This bean is configured to be the default transaction manager
for the <em>jbi</em> container. <em>jencks</em>is configured to use
the default transaction manager. This transaction manager provides transactional services
between the resource adapter (in this case the ActiveMQ resource adapter provided by the <em>jencks</em>
JCA container) and components the <em>jbi</em> container. </td>
</tr>
<tr>
<td class='confluenceTd'> <em>jmsFactory</em> </td>
<td class='confluenceTd'> This bean listens on port 61616 and provides a pooled ActiveMQ
connection. </td>
</tr>
</tbody></table>
</div>

<p>1. <em>jmsTemplate:</em> JmsTemplate is a Spring component which hides
the low level details when sending JMS messages. For additional information see: <a href="http://www.activemq.org/site/spring-support.html"
class="external-link" rel="nofollow">JmsTemplate</a>. jmsTemplate is not a component
in the <em>jbi</em> container. It is used by <em>inputSender</em>
and <em>outputSender</em>.</p>

<h2><a name="Basic-Usecase"></a>Use case</h2>

<p>ServiceMix is an Enterprise Service Bus (ESB) that is based on the Java Business
Integration (JBI) standard <a href="http://www.jcp.org/en/jsr/detail?id=208" class="external-link"
rel="nofollow">JSR 208</a>. The JBI-based design specifies a standards-based pluggable
architecture with a JVM-based runtime component called the Normalized Message Router (NMR).
The <em>Basic</em> example demonstrates how applications communicate via the ServiceMix
ESB, and the role that the NMR can play in that communication. Similar techniques could be
used to plug any  external <sup>1</sup> application or service into ServiceMix
(e.g. SAP, Peoplesoft, spreadsheets, POJOs, Webservices and EJBs) and allow it to communicate
with other external applications or components using ServiceMix itself.</p>

<p>A hypothetical business scenario, which extends the <em>Basic</em> Example,
is that of a department store distributor. This distributor sells products from multiple wholesalers
(suppliers) to various retailers (customers). The distributor presents a common interface
for product ordering to each of its department store customers. However, the distributor must
work with a different ordering interface for each wholesale suppliers for the products they
are buying.</p>

<p>Using an ESB, the distributor has developed a number of components to receive department
store orders and then dynamically route and transform these orders to the appropriate wholesaler.
The order processing flow is described as follows:</p>
<ol>
	<li>Using the distributor's web interface, a department store customer submits an order
for multiple products. An HTTP request is sent to the <em>OrderReceiver</em>,
an HTTP binding component (BC). <sup>3</sup></li>
	<li>The <em>OrderReceiver</em> sends the message to an <em>OrderRouter</em>
service engine (SE) <sup>4</sup> component. This SE is responsible for parsing
the order and deciding, based on the message content, which <em>OrderTransformer</em>
should receive which part of the message (i.e., an order for a product).</li>
	<li>The <em>OrderRouter</em> publishes the orders to the appropriate message
topics based on the message content. Specifically, the <em>OrderRouter</em> publishes
the messages based on which wholesaler sells the item.</li>
	<li>The <em>OrderTransformer</em> is a service engine component, which
modifies the message and puts it in a format which is readable by the wholesaler interface
that will fulfill the order.</li>
	<li>Each <em>OrderTransformer</em> sends the modified message to the <em>OrderProcessor</em>.</li>
	<li>The <em>OrderProcessor</em> is a binding component that has two functions:<br/>
a. It places an order to the appropriate wholesaler through the wholesaler's Webservice or
proprietary interface.<br/>
b. It also publishes a message about the order on a topic.</li>
	<li>The message on the topic is subsequently picked up by the <em>BusinessMonitor</em>
component via the <em>jmsTrace</em> component.</li>
	<li>The <em>BusinessMonitor</em> component monitors the orders for quality
assurance and business analytics, such as data mining.</li>
</ol>


<p>The following diagram illustrates this:</p>
<div class="panel" style="border-color: #ccc;border-style: solid;border-width: 1px;"><div
class="panelHeader" style="border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color:
#ccc;"><b>Department Store Distributor's Order Processing System</b></div><div
class="panelContent">
<p><span class="image-wrap" style="display: block; text-align: center"><img
src="/confluence/download/attachments/38885/basicflow_as_usecase.jpg?version=1&amp;modificationDate=1157535011000"
style="border: 0px solid black" /></span></p>
</div></div>
<ol>
	<li><em>External</em> means the application is outside of the ESB.</li>
	<li><em>Resource Adapter</em>: a resource adapter provides connectivity
between a specific external application and the ESB. In the <em>Basic</em> example
the jencks container provides a JMS resource adapter.</li>
	<li><em>Binding Component (BC)</em>: a BC provides connectivity to applications
that are external to the ESB.</li>
	<li><em>Service Engine (SE)</em>: a service engine provides business logic
and transformation services to other components within the enterprise service bus.</li>
</ol>


<h2><a name="Basic-RelatedDocumentation"></a>Related Documentation</h2>

<p>For more information on the following topics please see:</p>
<ul>
	<li><a href="http://www.activemq.org/site/spring-support.html" class="external-link"
rel="nofollow">ActiveMQ related components, <em>jmsFactory</em>, <em>jmsTemplate</em>,
<em>broker</em></a></li>
</ul>


<ul>
	<li><a href="http://jencks.org/" class="external-link" rel="nofollow">JCA Container,
<em>jencks</em></a></li>
</ul>


<ul>
	<li><a href="/confluence/display/SM/Quartz" title="Quartz">Quartz timer</a></li>
</ul>


<p>For a brief explanation of the XML tags in the <tt>servicemix.xml</tt>
file, please see:</p>
<ul>
	<li><a href="http://incubator.apache.org/servicemix/xml-schemas.html" class="external-link"
rel="nofollow">XSD</a></li>
</ul>


<style type='text/css'>/*<![CDATA[*/
table.ScrollbarTable  {border: none;padding: 3px;width: 100%;padding: 3px;margin: 0px;background-color:
#f0f0f0}
table.ScrollbarTable td.ScrollbarPrevIcon {text-align: center;width: 16px;border: none;}
table.ScrollbarTable td.ScrollbarPrevName {text-align: left;border: none;}
table.ScrollbarTable td.ScrollbarParent {text-align: center;border: none;}
table.ScrollbarTable td.ScrollbarNextName {text-align: right;border: none;}
table.ScrollbarTable td.ScrollbarNextIcon {text-align: center;width: 16px;border: none;}

/*]]>*/</style><div class="Scrollbar"><table class='ScrollbarTable'><tr><td
width='33%' class='ScrollbarPrevName'>&nbsp;</td><td width='33%' class='ScrollbarParent'><sup><a
href="/confluence/display/SM/4.+Examples"><img border='0' align='middle' src='/confluence/images/icons/up_16.gif'
width='8' height='8'></a></sup><a href="/confluence/display/SM/4.+Examples">4.
Examples</a></td><td width='33%' class='ScrollbarNextName'>&nbsp;<a
href="/confluence/display/SM/Bridge">Bridge</a></td><td class='ScrollbarNextIcon'><a
href="/confluence/display/SM/Bridge"><img border='0' align='middle' src='/confluence/images/icons/forwd_16.gif'
width='16' height='16'></a></td></tr></table></div>
    </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/SM/Basic">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=38885&revisedVersion=7&originalVersion=6">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/SM/Basic?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message