camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Better JMS Transport for CXF Webservice using Apache Camel
Date Wed, 07 Mar 2012 15:02: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/Better+JMS+Transport+for+CXF+Webservice+using+Apache+Camel">Better
JMS Transport for CXF Webservice using Apache Camel</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~dkulp">Daniel
Kulp</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" >{excerpt}Configuring JMS in Apache
CXF before Version 2.1.3 is possible but not really easy or nice. This article shows how to
use Apache Camel to provide a better JMS Transport for CXF.{excerpt} <br> <br></td></tr>
            <tr><td class="diff-changed-lines" >*Update:* Since CXF 2.1.3 there
is a new way of configuring JMS <span class="diff-changed-words">([<span class="diff-deleted-chars"style="color:#999;background-color:#fdd;text-decoration:line-through;">CXF20DOC:</span>Using</span>
the <span class="diff-changed-words">JMSConfigFeature<span class="diff-added-chars"style="background-color:
#dfd;">|http://cxf.apache.org/docs/using-the-jmsconfigfeature.html</span>]).</span>
It makes JMS config for CXF as easy as with Camel. Using Camel for JMS is still a good idea
if you want to use the rich feature of Camel for routing and other Integration Scenarios that
CXF does not support. <br></td></tr>
            <tr><td class="diff-unchanged" > <br>[You can find the original
announcement for this Tutorial and some additional info on Christian SchneiderĀ“s Blog|http://www.liquid-reality.de/display/liquid/2008/08/25/Better+JMS+Transport+for+CXF+Webservice+using+Apache+Camel]
<br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="BetterJMSTransportforCXFWebserviceusingApacheCamel-BetterJMSTransportforCXFWebserviceusingApacheCamel"></a>Better
JMS Transport for CXF Webservice using Apache Camel </h2>
<p>Configuring JMS in Apache CXF before Version 2.1.3 is possible but not really easy
or nice. This article shows how to use Apache Camel to provide a better JMS Transport for
CXF.</p>

<p><b>Update:</b> Since CXF 2.1.3 there is a new way of configuring JMS
(<a href="http://cxf.apache.org/docs/using-the-jmsconfigfeature.html" class="external-link"
rel="nofollow">Using the JMSConfigFeature</a>). It makes JMS config for CXF as easy
as with Camel. Using Camel for JMS is still a good idea if you want to use the rich feature
of Camel for routing and other Integration Scenarios that CXF does not support.</p>

<p><a href="http://www.liquid-reality.de/display/liquid/2008/08/25/Better+JMS+Transport+for+CXF+Webservice+using+Apache+Camel"
class="external-link" rel="nofollow">You can find the original announcement for this Tutorial
and some additional info on Christian SchneiderĀ“s Blog</a></p>


<h3><a name="BetterJMSTransportforCXFWebserviceusingApacheCamel-SohowtoconnectApacheCamelandCXF"></a>So
how to connect Apache Camel and CXF</h3>

<p>The best way to connect Camel and CXF is using the <a href="http://activemq.apache.org/camel/camel-transport-for-cxf.html"
class="external-link" rel="nofollow">Camel transport for CXF</a>. This is a camel
module that registers with cxf as a new transport. It is quite easy to configure.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;bean class=<span class="code-quote">"org.apache.camel.component.cxf.transport.CamelTransportFactory"</span>&gt;
  &lt;property name=<span class="code-quote">"bus"</span> ref=<span class="code-quote">"cxf"</span>
/&gt;
  &lt;property name=<span class="code-quote">"camelContext"</span> ref=<span
class="code-quote">"camelContext"</span> /&gt;
  &lt;property name=<span class="code-quote">"transportIds"</span>&gt;
    &lt;list&gt;
      &lt;value&gt;http:<span class="code-comment">//cxf.apache.org/transports/camel&lt;/value&gt;
</span>    &lt;/list&gt;
  &lt;/property&gt;
&lt;/bean&gt;
</pre>
</div></div>
<p>This bean registers with CXF and provides a new transport prefix camel:// that can
be used in CXF address configurations. The bean references a bean cxf which will be already
present in your config. The other refrenceis a camel context. We will later define this bean
to provide the routing config.</p>

<h3><a name="BetterJMSTransportforCXFWebserviceusingApacheCamel-HowisJMSconfiguredinCamel"></a>How
is JMS configured in Camel</h3>

<p>In camel you need two things to configure JMS. A ConnectionFactory and a JMSComponent.
As ConnectionFactory you can simply set up the normal Factory your JMS provider offers or
<a href="http://static.springframework.org/spring/docs/2.5.x/reference/xsd-config.html#xsd-config-body-schemas-jee-jndi-lookup-environment-single"
class="external-link" rel="nofollow">bind a JNDI ConnectionFactory</a>. In this example
we use the ConnectionFactory provided by ActiveMQ.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;bean id=<span class="code-quote">"jmsConnectionFactory"</span> class=<span
class="code-quote">"org.apache.activemq.ActiveMQConnectionFactory"</span>&gt;
  &lt;property name=<span class="code-quote">"brokerURL"</span> value=<span
class="code-quote">"tcp:<span class="code-comment">//localhost:61616"</span>
/&gt;
</span>&lt;/bean&gt;
</pre>
</div></div>
<p>Then we set up the JMSComponent. It offers a new transport prefix to camel that we
simply call jms. If we need several JMSComponents we can differentiate them by their name.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;bean id=<span class="code-quote">"jms"</span> class=<span class="code-quote">"org.apache.camel.component.jms.JmsComponent"</span>&gt;
  &lt;property name=<span class="code-quote">"connectionFactory"</span> ref=<span
class="code-quote">"jmsConnectionFactory"</span> /&gt;
  &lt;property name=<span class="code-quote">"useMessageIDAsCorrelationID"</span>
value=<span class="code-quote">"<span class="code-keyword">true</span>"</span>
/&gt;
&lt;/bean&gt;
</pre>
</div></div>
<p>You can find more details about the <a href="http://activemq.apache.org/camel/jms.html"
class="external-link" rel="nofollow">JMSComponent at the Camel Wiki</a>. For example
you find the complete configuration options and a JNDI sample there.</p>

<h3><a name="BetterJMSTransportforCXFWebserviceusingApacheCamel-SettinguptheCXFclient"></a>Setting
up the CXF client</h3>

<p>We will configure a simple CXF webservice client. It will use stub code generated
from a wsdl. The webservice client will be configured to use JMS directly. You can also use
a direct: Endpoint and do the routing to JMS in the Camel Context.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;client id=<span class="code-quote">"CustomerService"</span> xmlns=<span
class="code-quote">"http:<span class="code-comment">//cxf.apache.org/jaxws"</span>
xmlns:customer=<span class="code-quote">"http://customerservice.example.com/"</span>
</span>  serviceName=<span class="code-quote">"customer:CustomerServiceService"</span>
  endpointName=<span class="code-quote">"customer:CustomerServiceEndpoint"</span>
  address=<span class="code-quote">"camel:jms:queue:CustomerService"</span>
  serviceClass=<span class="code-quote">"com.example.customerservice.CustomerService"</span>&gt;
&lt;/client&gt;
</pre>
</div></div>
<p>We explicitly configure serviceName and endpointName so they are not read from the
wsdl. The names we use are arbitrary and have no further function but we set them to look
nice. The serviceclass points to the service interface that was generated from the wsdl. Now
the important thing is address. Here we tell cxf to use the camel transport, use the JmsComponent
who registered the prefix "jms" and use the queue "CustomerService".</p>

<h3><a name="BetterJMSTransportforCXFWebserviceusingApacheCamel-SettinguptheCamelContext"></a>Setting
up the CamelContext</h3>

<p>As we do not need additional routing an empty <a href="http://activemq.apache.org/camel/spring.html"
class="external-link" rel="nofollow">CamelContext</a> bean will suffice.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;camelContext id=<span class="code-quote">"camelContext"</span> xmlns=<span
class="code-quote">"http:<span class="code-comment">//activemq.apache.org/camel/schema/spring"</span>&gt;
</span>&lt;/camelContext&gt;
</pre>
</div></div>

<h3><a name="BetterJMSTransportforCXFWebserviceusingApacheCamel-RunningtheExample"></a>Running
the Example</h3>

<ul>
	<li><a href="/confluence/download/attachments/95908/cxfcamelexample.zip?version=2&amp;modificationDate=1219861188000">Download
the example project here</a></li>
</ul>


<ul>
	<li>Follow the readme.txt</li>
</ul>


<h3><a name="BetterJMSTransportforCXFWebserviceusingApacheCamel-Conclusion"></a>Conclusion</h3>

<p>As you have seen in this example you can use Camel to connect services to JMS easily
while being able to also use the rich integration features of Apache Camel.</p>

    </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/Better+JMS+Transport+for+CXF+Webservice+using+Apache+Camel">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=95908&revisedVersion=10&originalVersion=9">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Better+JMS+Transport+for+CXF+Webservice+using+Apache+Camel?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message