Scalable CXF consumer and producer using JMS transportPage edited by Andrei ShakirinChanges (1)
Full ContentJava Message Service (JMS) is wide spread and popular messaging API. As JMS is standardized, the same application code can successfully work with different JMS implementations: WS MQ, Active MQ, Tibco, Joram, BEA WebLogic, OpenJMS. Default CXF consumer and producer using JMSImplementing CXF client and service using JMS transport is trivial. WSDL binding and port should look like: <wsdl:binding name="Greeter_SOAPBinding" type="tns:Greeter"> <soap:binding style="document" transport="http://cxf.apache.org/transports/jms"/> … </wsdl:binding> <wsdl:service name="JMSGreeterService"> <wsdl:port binding="tns:JMSGreeterPortBinding" name="GreeterPort"> <jms:address destinationStyle="queue" jndiConnectionFactoryName="ConnectionFactory" jndiDestinationName="dynamicQueues/test.cxf.jmstransport.queue"> <jms:JMSNamingProperty name="java.naming.factory.initial" value="org.apache.activemq.jndi.ActiveMQInitialContextFactory"/> <jms:JMSNamingProperty name="java.naming.provider.url" value="tcp://localhost:61616"/> </jms:address> </wsdl:port> </wsdl:service> CXF clients and servers 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). Scalability problemsUnfortunately there are two main scalability drawbacks when using default JMS configuration:
Both aspects are critical for enterprise applications and their implementation is not an easy task. Is there any solution? Yes: Spring JMS functionality and CXF Features. Let discuss them in detail. Spring JMS functionalitySpring provides a number of useful classes that helps to implement scalable JMS application. Important for us are: org.springframework.jms.connection.CachingConnectionFactory CachingConnectionFactoryCachingConnectionFactory provides session pooling, consumers and producers cache. Bellow is a sample configuration of CachingConnectionFactory: <bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"> <property name="targetConnectionFactory"> <bean class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61616" /> </bean> </property> <property name="sessionCacheSize" value="20"/> <property name="cacheProducers" value="true"/> <property name="cacheConsumers" value="true"/> </bean> As you can see it is possible to set the size of the session pool and switch on producers and consumers caching. DefaultMessageListenerContainerDefaultMessageListenerContainer enables getting messages from the destination in parallel, using multiple threads. <bean id="queueContainerListener" class="org.springframework.jms.listener.DefaultMessageListenerContainer"> <property name="connectionFactory" ref="connectionFactory" /> <property name="destinationName" value="Q_WM_OUT" /> <property name="messageListener" ref="simpleListener" /> <property name="cacheLevel" value="3" /> <property name="concurrentConsumers" value="10" /> <property name="maxConcurrentConsumers" value="50" /> </bean> 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. CXF FeaturesAs the CXF JMS implementation is based the Spring JMS classes the user can benefit from described Spring JMS functionality. Server configuration<bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"> <property name="targetConnectionFactory"> <bean class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61616" /> </bean> </property> <property name="sessionCacheSize" value="20"/> <property name="cacheConsumers" value="true"/> </bean> <bean id="jmsConfig" class="org.apache.cxf.transport.jms.JMSConfiguration" p:connectionFactory-ref="cachingConnectionFactory" p:cacheLevel="3" p:concurrentConsumers="16" p:maxConcurrentConsumers="16" p:targetDestination="Q_HSC" p:wrapInSingleConnectionFactory="false" /> <jaxws:endpoint id=" JMSGreeterService" address="jms://" implementor="#JMSGreeterServiceImpl"> <jaxws:features> <bean class="org.apache.cxf.transport.jms.JMSConfigFeature"> <p:jmsConfig-ref="jmsConfig"> </bean> </jaxws:features> </jaxws:endpoint> You can see that the endpoint configuration contains the JMSConfigFeature that has a JMSConfiguration property. Client configuration<bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"> <property name="targetConnectionFactory"> <bean class="org.apache.activemq.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61616" /> </bean> </property> <property name="sessionCacheSize" value="20"/> <property name="cacheProducers" value="true"/> </bean> <bean id="jmsConfig" class="org.apache.cxf.transport.jms.JMSConfiguration" p:connectionFactory-ref="connectionFactory" p:targetDestination="Q_HSC" p:wrapInSingleConnectionFactory="false" /> <jaxws:client id="JMSGreeterService" address="jms://" serviceClass="com.sopera.services.tpoc.eventgenerator.EventGenerator”> <jaxws:features> <bean class="org.apache.cxf.transport.jms.JMSConfigFeature"> <property name="jmsConfig" ref="jmsConfig"/> </bean> </jaxws:features> </jaxws:client> Client configuration looks very similar to the server one except two things:
ConclusionIt is possible to achieve scalability of a CXF client and service using Spring JMS functionality and the CXF JMS Configuration Feature. References
Change Notification Preferences
View Online
|
View Changes
|
Add Comment
|
- [CONF] Apache CXF > Scalable CXF consumer and producer using... confluence
- [CONF] Apache CXF > Scalable CXF consumer and producer ... confluence
- [CONF] Apache CXF > Scalable CXF consumer and producer ... confluence
- [CONF] Apache CXF > Scalable CXF consumer and producer ... confluence
- [CONF] Apache CXF > Scalable CXF consumer and producer ... confluence
- [CONF] Apache CXF > Scalable CXF consumer and producer ... confluence
- [CONF] Apache CXF > Scalable CXF consumer and producer ... confluence
- [CONF] Apache CXF > Scalable CXF consumer and producer ... confluence
