camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [CONF] Apache Camel > Better JMS Transport for CXF Webservice using Apache Camel
Date Tue, 22 Sep 2009 18:53:01 GMT
    <base href="">
            <link rel="stylesheet" href="/confluence/s/1519/1/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
<body style="background-color: white" bgcolor="white">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
     <h2><a href="">Better
JMS Transport for CXF Webservice using Apache Camel</a></h2>
     <h4>Page <b>edited</b> by             <a href="">Daniel
     <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

<p><b>Update:</b> Since CXF 2.1.3 there is a new way of configuring JMS
(<a href="/confluence/display/CXF20DOC/Using+the+JMSConfigFeature" title="Using the JMSConfigFeature">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=""
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=""
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>
  &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;value&gt;http:<span class="code-comment">//;/value&gt;
</span>    &lt;/list&gt;
<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=""
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
  &lt;property name=<span class="code-quote">"brokerURL"</span> value=<span
class="code-quote">"tcp:<span class="code-comment">//localhost:61616"</span>
<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>
<p>You can find more details about the <a href=""
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">//"</span>
xmlns:customer=<span class="code-quote">""</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;
<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=""
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">//"</span>&gt;

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

	<li><a href="/confluence/download/attachments/95908/">Download
the example project here</a></li>

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

<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 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