cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache CXF > Scalable CXF consumer and producer using JMS transport
Date Sun, 02 Oct 2011 12:17:01 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/15/_/styles/combined.css?spaceKey=CXF&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/CXF/Scalable+CXF+consumer+and+producer+using+JMS+transport">Scalable
CXF consumer and producer using JMS transport</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~ashakirin">Andrei
Shakirin</a>
    </h4>
        <br/>
                         <h4>Changes (2)</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. Default CXF consumer and procuder
using JMS <br>Implementing CXF client and service using JMS transport is trivial. Basically,
it is enough to configure two things in WSDL:  <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-added-words"style="background-color:
#dfd;">*</span> a) specify jms transport URI in binding element; <br></td></tr>
            <tr><td class="diff-changed-lines" ><span class="diff-added-words"style="background-color:
#dfd;">*</span> b) define jms address in port element. <br></td></tr>
            <tr><td class="diff-unchanged" >WSDL binding and port should look
like: <br> <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>Java Message Service (JMS) is wide spread and popular messaging java interface.
As far as JMS is standardized in JEE, the same application code can successfully work with
different JMS implementations: WS MQ, Active MQ, Tibco, Joram, BEA WebLogic, OpenJMS.<br/>
CXF provides a transport that enables endpoints to use JMS queues and topics. </p>

<h2><a name="ScalableCXFconsumerandproducerusingJMStransport-DefaultCXFconsumerandprocuderusingJMS"></a>Default
CXF consumer and procuder using JMS</h2>
<p>Implementing CXF client and service using JMS transport is trivial. Basically, it
is enough to configure two things in WSDL: </p>
<ul>
	<li>a) specify jms transport URI in binding element;</li>
	<li>b) define jms address in port element.<br/>
WSDL binding and port should look like:</li>
</ul>


<p>&lt;wsdl:binding name="Greeter_SOAPBinding" type="tns:Greeter"&gt;<br/>
        &lt;soap:binding style="document" transport="http://cxf.apache.org/transports/jms"/&gt;<br/>
…<br/>
&lt;/wsdl:binding&gt;</p>

<p>&lt;wsdl:service name="JMSGreeterService"&gt;<br/>
        &lt;wsdl:port binding="tns:JMSGreeterPortBinding" name="GreeterPort"&gt;<br/>
            &lt;jms:address<br/>
                destinationStyle="queue"<br/>
                jndiConnectionFactoryName="ConnectionFactory" <br/>
jndiDestinationName="dynamicQueues/test.cxf.jmstransport.queue"&gt;<br/>
               &lt;jms:JMSNamingProperty name="java.naming.factory.initial" value="org.apache.activemq.jndi.ActiveMQInitialContextFactory"/&gt;<br/>
                  &lt;jms:JMSNamingProperty name="java.naming.provider.url" value="tcp://localhost:61616"/&gt;<br/>
           &lt;/jms:address&gt;<br/>
        &lt;/wsdl:port&gt;<br/>
 &lt;/wsdl:service&gt;</p>

<p>CXF client and server implemented in java or using Spring configuration magically
work for this WSDL (under the hood CXF selects correct JMS Conduit and Destination based on
address URL). <br/>
Details are described in <a href="http://cxf.apache.org/docs/jms-transport.html" class="external-link"
rel="nofollow">http://cxf.apache.org/docs/jms-transport.html</a>. CXF also delivers
jms_pubsub and jms_pubsub examples illustrating using JMS transport with default settings
for ActiveMQ.</p>

<p>Unfortunately there are two main scalability drawbacks in default JMS configuration:<br/>
1. It doesn't provide sessions pooling and consumers/producers cache.<br/>
2. Default JMS message consumer is single threaded. It means that only one thread will get
messages from the queue or topic and pass them to further processing.</p>

<p>Both aspects are critical for enterprise application and their implementation is
not easy task. Is there any solution? Yes: Spring JMS functionality and CXF Features. Let
discuss them in detail.</p>

<p>1.	Spring JMS functionality<br/>
Spring provides a number of useful classes that helps to implement scalable JMS application.
Important for us are: org.springframework.jms.connection.CachingConnectionFactory<br/>
org.springframework.jms.listener.DefaultMessageListenerContainer</p>

<p>1.1. CachingConnectionFactory provides sessions pool, consumers and producers cache.
Bellow is a sample configuration of CachingConnectionFactory:</p>

<p>&lt;bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"&gt;<br/>
	&lt;property name="targetConnectionFactory"&gt;<br/>
		&lt;bean class="org.apache.activemq.ActiveMQConnectionFactory"&gt;<br/>
			&lt;property name="brokerURL" value="tcp://localhost:61616" /&gt;<br/>
		&lt;/bean&gt;<br/>
	&lt;/property&gt;<br/>
	&lt;property name="sessionCacheSize" value="20"/&gt;<br/>
	&lt;property name="cacheProducers" value="true"/&gt;<br/>
	&lt;property name="cacheConsumers" value="true"/&gt;<br/>
&lt;/bean&gt;</p>

<p>As you can see it is possible to set size of session pool and switch on producers
and consumers caching.</p>

<p>1.2.	DefaultMessageListenerContainer enables getting messages from the destination
in parallel, using multiple threads.<br/>
Configuration of DefaultMessageListenerContainer looks like:</p>

<p>	&lt;bean id="queueContainerListener"<br/>
	class="org.springframework.jms.listener.DefaultMessageListenerContainer"&gt;<br/>
		&lt;property name="connectionFactory" ref="connectionFactory" /&gt;<br/>
		&lt;property name="destinationName" value="Q_WM_OUT" /&gt;<br/>
		&lt;property name="messageListener" ref="simpleListener" /&gt;<br/>
		&lt;property name="cacheLevel" value="3" /&gt;<br/>
		&lt;property name="concurrentConsumers" value="10" /&gt;<br/>
		&lt;property name="maxConcurrentConsumers" value="50" /&gt;<br/>
	&lt;/bean&gt;	<br/>
It is possible to define initial and maximal number of concurrent message consumer threads,
cache level (3- cache consumers, 2 – cache session, 1 – no caching), specify message listener
class (implementing MessageListener interface) and connection factory.<br/>
You can see that Spring provides solution for both mentioned scalability aspects. But how
we can use it in CXF? </p>

<p>2.	CXF Features.<br/>
As far as CXF JMS implementation is Spring based, user can benefit from described Spring JMS
functionality. CXF provides a possibility to configure different Spring aspects in JMS transport
using Features. A Feature is something that is able to customize a Server, Client, or Bus,
typically adding capabilities. In our case we will add Feature in ws:endpoint and ws:client
to tune JMS transport.</p>

<p>Server configuration:</p>

<p>&lt;bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"&gt;<br/>
	&lt;property name="targetConnectionFactory"&gt;<br/>
		&lt;bean class="org.apache.activemq.ActiveMQConnectionFactory"&gt;<br/>
			&lt;property name="brokerURL" value="tcp://localhost:61616" /&gt;<br/>
		&lt;/bean&gt;<br/>
	&lt;/property&gt;<br/>
	&lt;property name="sessionCacheSize" value="20"/&gt;<br/>
	&lt;property name="cacheConsumers" value="true"/&gt;<br/>
&lt;/bean&gt;</p>

<p>&lt;bean id="jmsConfig" class="org.apache.cxf.transport.jms.JMSConfiguration"<br/>
		p:connectionFactory-ref="cachingConnectionFactory"<br/>
		p:cacheLevel="3" <br/>
		p:concurrentConsumers="16"<br/>
		p:maxConcurrentConsumers="16"<br/>
		p:targetDestination="Q_HSC"<br/>
		p:wrapInSingleConnectionFactory="false"<br/>
	/&gt;</p>

<p>	&lt;jaxws:endpoint id=" JMSGreeterService" address="jms://"<br/>
		implementor="#JMSGreeterServiceImpl"&gt;<br/>
		&lt;jaxws:features&gt;<br/>
			&lt;bean class="org.apache.cxf.transport.jms.JMSConfigFeature"&gt;<br/>
				&lt;p:jmsConfig-ref="jmsConfig"&gt;<br/>
			&lt;/bean&gt;<br/>
		&lt;/jaxws:features&gt;<br/>
	&lt;/jaxws:endpoint&gt;</p>

<p>You can see that endpoint configuration containing JMSConfigFeature feature that
has a JMSConfiguration property. JMSConfiguration supports all settings that we have seen
in Spring DefaultMessageListenerContainer: cached connection factory with session pool size,
number of concurrent consumers, cache level. All settings of JMSConfiguration are described
in details in <a href="http://cxf.apache.org/docs/using-the-jmsconfigfeature.html" class="external-link"
rel="nofollow">http://cxf.apache.org/docs/using-the-jmsconfigfeature.html</a>.<br/>
Using this configuration server application can be tuned to achieve optimal performance in
target environment.</p>

<p>Client configuration:</p>

<p>&lt;bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"&gt;<br/>
	&lt;property name="targetConnectionFactory"&gt;<br/>
		&lt;bean class="org.apache.activemq.ActiveMQConnectionFactory"&gt;<br/>
			&lt;property name="brokerURL" value="tcp://localhost:61616" /&gt;<br/>
		&lt;/bean&gt;<br/>
	&lt;/property&gt;<br/>
	&lt;property name="sessionCacheSize" value="20"/&gt;<br/>
	&lt;property name="cacheProducers" value="true"/&gt;<br/>
&lt;/bean&gt;</p>

<p>&lt;bean id="jmsConfig" class="org.apache.cxf.transport.jms.JMSConfiguration"<br/>
p:connectionFactory-ref="connectionFactory" p:targetDestination="Q_HSC"<br/>
		p:wrapInSingleConnectionFactory="false" /&gt; </p>

<p>&lt;jaxws:client id="JMSGreeterService" address="jms://"<br/>
	serviceClass="com.sopera.services.tpoc.eventgenerator.EventGenerator”&gt;<br/>
		&lt;jaxws:features&gt;<br/>
			&lt;bean class="org.apache.cxf.transport.jms.JMSConfigFeature"&gt;<br/>
				&lt;property name="jmsConfig" ref="jmsConfig"/&gt;<br/>
			&lt;/bean&gt;<br/>
		&lt;/jaxws:features&gt;<br/>
	&lt;/jaxws:client&gt;</p>


<p>Client configuration looks very similar to the server one except two things:<br/>
a)	CachingConnectionFactory  activates producers caching instead consumers caching;<br/>
b)	JMSConfiguration hasn’t concurrent consumers settings: client concurrency is under application
control and can be implemented using standard Java concurrency API.</p>


<p>Conclusion: it is possible to achieve scalability of CXF client and service using
Spring JMS functionality and CXF JMS Configuration Feature. It is not necessary to write any
line of code, just configure and leverage already existing stuff.</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/CXF/Scalable+CXF+consumer+and+producer+using+JMS+transport">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=27828015&revisedVersion=2&originalVersion=1">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CXF/Scalable+CXF+consumer+and+producer+using+JMS+transport?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message