JMS Transport - 6.1

Talend ESB Service Developer Guide

EnrichVersion
6.1
EnrichProdName
Talend Data Fabric
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for ESB
Talend Real-Time Big Data Platform
task
Design and Development
Installation and Upgrade
EnrichPlatform
Talend ESB

CXF provides a transport plug-in that enables endpoints to use Java Message Service (JMS) queues and topics. CXF's JMS transport plug-in uses the Java Naming and Directory Interface (JNDI) to locate and obtain references to the JMS provider that brokers for the JMS destinations. Once CXF has established a connection to a JMS provider, CXF supports the passing of messages packaged as either a JMS ObjectMessage or a JMS TextMessage. The JMS transport also supports the SOAP over JMS specification, see SOAP over JMS 1.0 support.

Standard JMS transport configuration in CXF is done by defining a JMSConduit or JMSDestination, discussed below. There is however an alternative configuration option more conformant to Spring dependency injection, see Using the JMSConfigFeature.

JMS Namespaces

WSDL Namespace

The WSDL extensions for defining a JMS endpoint are defined in the namespace http://cxf.apache.org/transports/jms . In order to use the JMS extensions you will need to add the namespace definition shown below to the definitions element of your contract.

Example 31. JMS Extension Namespace

xmlns:jms="http://cxf.apache.org/transports/jms"

Configuration Namespaces

In order to use the JMS configuration properties you will need to add the line shown below to the beans element of your configuration.

Example 32. JMS Configuration Namespaces

xmlns:jms="http://cxf.apache.org/transports/jms"

Basic Endpoint Configuration

JMS endpoints need to know certain basic information about how to establish a connection to the proper destination. This information can be provided in one of two places: WSDL or XML configuration. The following configuration elements which are described can be used in both the client side Conduits and the server side Destinations.

Using WSDL

The JMS destination information is provided using the jms:address element and its child, the jms:JMSNamingProperties element. The jms:address element's attributes specify the information needed to identify the JMS broker and the destination. The jms:JMSNamingProperties element specifies the Java properties used to connect to the JNDI service.

The address element

The basic configuration for a JMS endpoint is done by using a jms:address element as the child of your service's port element. The jms:address element uses the attributes described below to configure the connection to the JMS broker.

Attribute

Description

destinationStyle

Specifies if the JMS destination is a JMS queue or a JMS topic.

jndiConnectionFactoryName

Specifies the JNDI name bound to the JMS connection factory to use when connecting to the JMS destination.

jndiDestinationName

Specifies the JNDI name bound to the JMS destination to which requests are sent.

jndiReplyDestinationName

Specifies the JNDI name bound to the JMS destinations where replies are sent. This attribute allows you to use a user defined destination for replies.

connectionUserName

Specifies the username to use when connecting to a JMS broker.

connectionPassword

Specifies the password to use when connecting to a JMS broker.

The JMSNamingProperties element

To increase interoperability with JMS and JNDI providers, the jms:address element has a child element, jms:JMSNamingProperties , that allows you to specify the values used to populate the properties used when connecting to the JNDI provider. The jms:JMSNamingProperties element has two attributes: name and value . The name attribute specifies the name of the property to set. The value attribute specifies the value for the specified property. The jms:JMSNamingProperties element can also be used for specification of provider specific properties. The following is a list of common JNDI properties that can be set:

  • java.naming.factory.initial

  • java.naming.provider.url

  • java.naming.factory.object

  • java.naming.factory.state

  • java.naming.factory.url.pkgs

  • java.naming.dns.url

  • java.naming.authoritative

  • java.naming.batchsize

  • java.naming.referral

  • java.naming.security.protocol

  • java.naming.security.authentication

  • java.naming.security.principal

  • java.naming.security.credentials

  • java.naming.language

  • java.naming.applet

For more details on what information to use in these attributes, check your JNDI provider's documentation and consult the Java API reference material.

Using a named reply destination

By default, CXF endpoints using JMS create a temporary queue for sending replies back and forth. You can change this behavior by setting the jndiReplyDestinationName attribute in the endpoint's contract. A client endpoint will listen for replies on the specified destination and it will specify the value of the attribute in the ReplyTo field of all outgoing requests. A service endpoint will use the value of the jndiReplyDestinationName attribute as the location for placing replies if there is no destination specified in the request's ReplyTo field.

A static reply queue can not be shared by several instances of the service client. Please use a dynamic reply queue or different queue names per instance instead.

The following example shows an example of a JMS WSDL port specification.

Example 33. JMS WSDL Port Specification

<service name="JMSService">
   <port binding="tns:Greeter_SOAPBinding" name="SoapPort">
      <jms:address jndiConnectionFactoryName="ConnectionFactory"
         jndiDestinationName="dynamicQueues/test.cxf.jmstransport">
         <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>
   </port>
</service>

Using Configuration

In addition to using the WSDL file to specify the connection information for a JMS endpoint, you can also supply it in the endpoint's XML configuration. The information in the configuration file will override the information in the endpoint's WSDL file.

Configuration elements

You configure a JMS endpoint using one of the following configuration elements:

  • jms:conduit : The jms:conduit element contains the configuration for a consumer endpoint. It has one attribute, name , whose value takes the form

    {WSDLNamespace}WSDLPortName.jms-conduit
  • jms:destination : The jms:destination element contains the configuration for a provider endpoint. It has one attribute, name , whose value takes the form

    {WSDLNamespace}WSDLPortName.jms-destination

    .

The address element

JMS connection information is specified by adding a jms:address child to the base configuration element. The jms:address element used in the configuration file is identical to the one used in the WSDL file. Its attributes are listed in the address element's attribute table . Like the jms:address element in the WSDL file, the jms:address configuration element also has a jms:JMSNamingProperties child element that is used to specify additional information used to connect to a JNDI provider.

Example 34. Addressing Information in a Configuration File

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:ct="http://cxf.apache.org/configuration/types"
   xmlns:jms="http://cxf.apache.org/transports/jms"
   xsi:schemaLocation="
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://cxf.apache.org/jaxws 
      http://cxf.apache.org/schemas/jaxws.xsd
      http://cxf.apache.org/transports/jms 
      http://cxf.apache.org/schemas/configuration/jms.xsd">
   <jms:conduit 
      name="{http://cxf.apache.org/jms_endpt}HelloJMSPort.jms-conduit">
      <jms:address destinationStyle="queue"
         jndiConnectionFactoryName="myConnectionFactory"
         jndiDestinationName="myDestination"
         jndiReplyDestinationName="myReplyDestination"
         connectionUserName="testUser"
         connectionPassword="testPassword">
         <jms:JMSNamingProperty name="java.naming.factory.initial"
            value="org.apache.cxf.transport.jms.MyInitialContextFactory"/>
         <jms:JMSNamingProperty name="java.naming.provider.url"
            value="tcp://localhost:61616"/>
      </jms:address>
   </jms:conduit>
</beans>

Consumer Endpoint Configuration

JMS consumer endpoints specify the type of messages they use. JMS consumer endpoint can use either a JMS ObjectMessage or a JMS TextMessage . When using an ObjectMessage the consumer endpoint uses a byte[] as the method for storing data into and retrieving data from the JMS message body. When messages are sent, the message data, including any formating information, is packaged into a byte[] and placed into the JMS message body before it is placed on the wire. When messages are received, the consumer endpoint will attempt to unmarshall the data stored in the JMS body as if it were packed in a byte[] .

When using a TextMessage , the consumer endpoint uses a string as the method for storing and retrieving data from the JMS message body. When messages are sent, the message information, including any format-specific information, is converted into a string and placed into the JMS message body. When messages are received the consumer endpoint will attempt to unmashall the data stored in the JMS message body as if it were packed into a string.

When native JMS applications interact with CXF consumers, the JMS application is responsible for interpreting the message and the formatting information. For example, if the CXF contract specifies that the binding used for a JMS endpoint is SOAP, and the messages are packaged as TextMessage , the receiving JMS application will get a text message containing all of the SOAP envelope information.

Consumer endpoint can be configured by both XML configuration and via WSDL.

Using Configuration
Specifying the message type

You can specify the message type supported by the consumer endpoint using a jms:runtimePolicy element that has a single attribute:

  • messageType - Specifies how the message data will be packaged as a JMS message. text specifies that the data will be packaged as a TextMessage . binary specifies that the data will be packaged as an ObjectMessage .

The following example shows a configuration entry for configuring a JMS consumer endpoint.

Example 35. Configuration for a JMS Consumer Endpoint

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:ct="http://cxf.apache.org/configuration/types"
   xmlns:jms="http://cxf.apache.org/transports/jms"
   xsi:schemaLocation="
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans.xsd"
      http://cxf.apache.org/jaxws 
      http://cxf.apache.org/schemas/jaxws.xsd
      http://cxf.apache.org/transports/jms 
      http://cxf.apache.org/schemas/configuration/jms.xsd">
...
   <jms:conduit 
      name="{http://cxf.apache.org/jms_endpt}HelloJMSPort.jms-conduit">
      <jms:address ... >
         ...
      </jms:address>
      <jms:runtimePolicy messageType="binary"/>
      ...
   </jms:conduit>
...
</beans>

The id on the jms:conduit is in the form of { WSDLNamespace}WSDLPortName.jms-conduit . This provides CXF with the information so that it can associate the configuration with your service's endpoint.

Using WSDL

The type of messages accepted by a JMS consumer endpoint is configured using the optional jms:client element. The jms:client element is a child of the WSDL port element and has one attribute:

  • messageType - Specifies how the message data will be packaged as a JMS message. text specifies that the data will be packaged as a TextMessage . binary specifies that the data will be packaged as an ObjectMessage.

Service Endpoint Configuration

JMS service endpoints have a number of behaviors that are configurable in the contract. These include:

  • how messages are correlated

  • the use of durable subscriptions

  • if the service uses local JMS transactions

  • the message selectors used by the endpoint

Service endpoints can be configure in one of two ways:

  • Configuration

  • WSDL

Using Configuration
Specifying configuration data

Using the jms:destination elements you can configure your service's endpoint. You can specify the service endpoint's behaviors using the jms:runtimePolicy element that has a the following attributes:

Attribute

Description

useMessageIDAsCorrelationID

Specifies whether the JMS broker will use the message ID to correlate messages. The default is false .

durableSubscriberName

Specifies the name used to register a durable subscription.

messageSelector

Specifies the string value of a message selector to use. For more information on the syntax used to specify message selectors, see the JMS 1.1 specification.

transactional

Specifies whether the local JMS broker will create transactions around message processing. The default is false .

The following example shows a CXF configuration entry for configuring a JMS service endpoint.

Example 36. Configuration for a JMS Service Endpoint

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:ct="http://cxf.apache.org/configuration/types"
   xmlns:jms="http://cxf.apache.org/transports/jms"
   xsi:schemaLocation="
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans.xsd"
      http://cxf.apache.org/jaxws 
      http://cxf.apache.org/schemas/jaxws.xsd
      http://cxf.apache.org/transports/jms 
      http://cxf.apache.org/schemas/configuration/jms.xsd">
...
   <jms:destination 
      name="{http://cxf.apache.org/jms_endpt}HelloJMSPort.jms-destination">
      <jms:address ... >
         ...
      </jms:address>
         ...
      <jms:runtimePolicy messageSelector="cxf_message_selector"
         useMessageIDAsCorrelationID="true"
         transactional="true"
         durableSubscriberName="cxf_subscriber" />
      ...
   </jms:destination>
...
</beans>

Using WSDL

Service endpoint behaviors are configured using the optional jms:server element. The jms:server element is a child of the WSDL port element and has the following attributes:

Attribute

Description

useMessageIDAsCorrelationID

Specifies whether JMS will use the message ID to correlate messages. The default is false .

durableSubscriberName

Specifies the name used to register a durable subscription.

messageSelector

Specifies the string value of a message selector to use. For more information on the syntax used to specify message selectors, see the JMS 1.1 specification.

transactional

Specifies whether the local JMS broker will create transactions around message processing. The default is false . Currently, this is not supported by the runtime.

JMS Runtime Configuration

In addition to configuring the externally visible aspects of your JMS endpoint, you can also configure aspects of its internal runtime behavior. There are three types of runtime configuration:

  • Session pool configuration (common to both services and consumers)

  • Consumer specific configuration

  • Service specific configuration

Session Pool Configuration

You configure an endpoint's JMS session pool using the jms:sessionPoolConfig element. This property allows you to set a high and low water mark for the number of JMS sessions an endpoint will keep pooled. The endpoint is guaranteed to maintain a pool of sessions equal to the low water mark and to never pool more sessions than specified by the high water mark. The jms:sessionPool element's attributes, listed below, specify the high and low water marks for the endpoint's JMS session pool.

Attribute

Description

lowWaterMark

Specifies the minimum number of JMS sessions pooled by the endpoint. The default is 20.

highWaterMark

Specifies the maximum number of JMS sessions pooled by the endpoint. The default is 500.

The following example shows an example of configuring the session pool for a CXF JMS service endpoint.

Example 37. JMS Session Pool Configuration

<jms:destination 
name="{http://cxf.apache.org/jms_endpit}HelloJMSPort.jms-destination">
   ...
   <jms:sessionPool lowWaterMark="10" highWaterMark="5000" />
</jms:destination>

The jms:sessionPool element can also be used within a jms:conduit .

Consumer Specific Runtime Configuration

The JMS consumer configuration allows you to specify two runtime behaviors:

  • the number of milliseconds the consumer will wait for a response.

  • the number of milliseconds a request will exist before the JMS broker can remove it.

You use the jms:clientConfig element to set JMS consumer runtime behavior. This element's attributes, listed in the following table, specify the configuration values for consumer runtime behavior.

Attribute

Description

clientReceiveTimeout

Specifies the amount of time, in milliseconds, that the endpoint will wait for a response before it times out and issues an exception. The default value is 2000.

messageTimeToLive

Specifies the amount of time, in milliseconds, that a request can remain unrecieved before the JMS broker can delete it. The default value is 0 which specifies that the message can never be deleted.

The following example shows a configuration fragment that sets the consumer endpoint's request lifetime to 500 milliseconds and its timeout value to 500 milliseconds.

Example 38. JMS Consumer Endpoint Runtime Configuration

<jms:conduit 
name="{http://cxf.apache.org/jms_endpt}HelloJMSPort.jms-conduit">
   ...
   <jms:clientConfig clientReceiveTimeout="500"
      messageTimeToLive="500" />
</jms:conduit>

Service Specific Runtime Configuration

The JMS service configuration allows you to specify to runtime behaviors:

  • the amount of time a response message can remain unreceived before the JMS broker can delete it.

  • the client identifier used when creating and accessing durable subscriptions.

The jms:serverConfig element is used to specify the service runtime configuration. This element's attributes, listed below, specify the configuration values that control the service's runtime behavior.

Attribute

Description

messageTimeToLive

Specifies the amount of time, in milliseconds, that a response can remain unread before the JMS broker is allowed to delete it. The default is 0 which specifies that the message can live forever.

durableSubscriptionClientId

Specifies the client identifier the endpoint uses to create and access durable subscriptions.

The following example shows a configuration fragment that sets the service endpoint's response lifetime to 500 milliseconds and its durable subscription client identifier to jms-test-id .

Example 39. JMS Service Endpoint Runtime Configuration

<jms:destination 
   id="{http://cxf.apache.org/jms_endpt}HelloJMSPort.jms-destination">
   <jms:address ... >
      ...
   </jms:address>
   <jms:serverConfig messageTimeToLive="500"
      durableSubscriptionClientId="jms-test-id" />
</jms:destination>

SOAP over JMS 1.0 support

The [JMS Transport] offers an alternative messaging mechanism to SOAP over HTTP. SOAP over JMS offers more reliable and scalable messaging support than SOAP over HTTP. The SOAP over JMS specification is aimed at a set of standards for the transport of SOAP messages over JMS. Its main purpose is to ensure interoperability between the implementations of different Web services vendors. CXF supports and is compliant with this specification.

SOAP over JMS Namespace
JMS URI

JMS endpoints need to know the address information for establishing connections to the proper destination. SOAP over JMS implements the URI Scheme for Java Message Service 1.0 .

JMS URI Scheme

jms:<variant>:<destination name>?param1=value1&param2=value2

Variants

Prefix

Description

jndi

Destination name is a jndi queue name

jndi-topic

Destination name is a jndi topic name

queue

Destination is a queue name resolved using JMS

topic

Destination is a topic name resolved using JMS

Further parameters can be added as query parameters in the URI.

For example:

jms:jndi:SomeJndiNameForDestination?jndiInitialContextFactory=   //
   org.apache.activemq.jndi.ActiveMQInitialContextFactory&   //
   jndiURL=tcp://localhost:61616&priority=3&   //
   jms:queue:ExampleQueueName?timeToLive=1000
JMS parameters

Query Parameter

From Version

DefaultValue

Description

conduitIdSelectorPrefix

3.0.0

If set then this string will be the prefix for all correlation ids the conduit creates and also be used in the selector for listening to replies

deliveryMode

PERSISTENT

NON_PERSISTENT messages will kept only in memory

PERSISTENT messages will be saved to disk

durableSubscriptionClientId

3.0.1

Optional Client identifier for the connection. The purpose is to associate a connection with a state maintained on behalf of the client by a provider. The only such state identified by the JMS API is that required to support durable subscriptions.

durableSubscriptionName

3.0.0

jndiConnectionFactoryName

ConnectionFactory

Specifies the JNDI name bound to the JMS connection factory to use when connecting to the JMS destination.

jndiInitialContextFactory

Specifies the fully qualified Java class name of the "InitialContextFactory" implementation class to use.

jndiTransactionManagerName

3.0.0

Name of the JTA TransactionManager. Will be searched in spring, blueprint and jndi.

If a transaction manager is found then JTA transactions will be enabled. See details below.

jndiURL

Specifies the JNDI provider URL

jndi-*

Additional parameters for a JNDI provider

messageType

3.0.0

byte

JMS message type used by CXF (byte, text or binary)

password

3.0.0

Password for creating the connection. Using this in the URI is discouraged

priority

3.0.0

4

Priority for the messages. See your JMS provider documentation for details. Values range from 0 to 9 where 0 is lowest priority

replyToName

Specifies the JNDI name bound to the JMS destinations where replies are sent

receiveTimeout

3.0.0

60000

Timeout in milliseconds the client waits for a reply in case of request / repy exchanges

reconnectOnException

deprecated in 3.0.0

true

Should the transport reconnect in case of exceptions. From version 3.0.0 on the transport will always reconnect in case of exceptions

sessionTransacted

3.0.0

false

Set to true for resource local transactions. Do not set if you use JTA

timeToLive

0

Time (in ms) after which the message will be discarded by the jms provider

topicReplyToName

Reply to messages on a topic with this name. Depending on the variant this is either a jndi or jms name.

useConduitIdSelector

3.0.0

true

Each conduit is assigned with a UUID. If set to true this conduit id will be the prefix for all correlation ids. This allows several endpoints to share a JMS queue or topic

username

3.0.0

Username for creating the connection

Some of these attributes are specified in the JMS URI specification.

WSDL Extension

The WSDL extensions for defining a JMS endpoint use a special namespace. In order to use the JMS WSDL extensions you will need to add the namespace definition shown below to the definitions element of your contract.

Various JMS properties may be set in three places in the WSDL — the binding, the service, and the port. Values specified at the service will propagate to all ports. Values specified at the binding will propagate to all ports using that binding. For example, if the jndiInitialContextFactory is indicated for a service, it will be used for all of the port elements it contains.

JMS Properties. For details refer to the URI query parameters with the same name:

Name

deliveryMode

jndiConnectionFactoryName

jndiInitialContextFactory

jndiURL

replyToName

priority

timeToLive

jndiContextParameter

Here is an example:

Example 40. Ways to define a Service with JMS transport

<wsdl11:binding name="exampleBinding">
    <soapjms:jndiContextParameter name="name" value="value"/>
    <soapjms:jndiConnectionFactoryName>
       ConnectionFactory
    </soapjms:jndiConnectionFactoryName>
    <soapjms:jndiInitialContextFactory>
    org.apache.activemq.jndi.ActiveMQInitialContextFactory
    </soapjms:jndiInitialContextFactory>
    <soapjms:jndiURL>tcp://localhost:61616</soapjms:jndiURL>
    <soapjms:deliveryMode>PERSISTENT</soapjms:deliveryMode>
    <soapjms:priority>5</soapjms:priority>
    <soapjms:timeToLive>200</soapjms:timeToLive>
</wsdl11:binding>

<wsdl11:service name="exampleService">
    <soapjms:jndiInitialContextFactory>
       com.example.jndi.InitialContextFactory
    </soapjms:jndiInitialContextFactory>
    <soapjms:timeTolive>100</soapjms:timeToLive>
    <wsdl11:port name="quickPort" binding="tns:exampleBinding">
      <soapjms:timeToLive>10</soapjms:timeToLive>
    </wsdl11:port>
    <wsdl11:port name="slowPort" binding="tns:exampleBinding">
      ...
    </wsdl11:port>
</wsdl11:service>

If a property is specified at multiple levels, the setting at the most granular level takes precedence (port first, then service, then binding). In the above example, notice the timeToLive property — for the quickPort port, the value will be 10ms (specified at the port level). For the slowPort port, the value will be 100ms (specified at the service level). In this example, the setting in the binding will always be overridden.

WSDL Usage

For this example:

Example 41. Greeter Service with JMS transaport

<wsdl:definitions name="JMSGreeterService"
  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
  xmlns:tns="http://cxf.apache.org/jms_greeter" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
  xmlns:x1="http://cxf.apache.org/jms_greeter/types" 
  xmlns:soapjms="http://www.w3.org/2010/soapjms/" 
  name="JMSGreeterService"
  targetNamespace="http://cxf.apache.org/jms_greeter">
    ...
   <wsdl:binding name="JMSGreeterPortBinding" 
      type="tns:JMSGreeterPortType">
      <soap:binding style="document"
         transport="http://www.w3.org/2010/soapjms/" />
      <soapjms:jndiContextParameter name="name"
         value="value" />
      <soapjms:jndiConnectionFactoryName>
         ConnectionFactory
      </soapjms:jndiConnectionFactoryName>
      <soapjms:jndiInitialContextFactory>
         org.apache.activemq.jndi.ActiveMQInitialContextFactory
      </soapjms:jndiInitialContextFactory>
      <soapjms:jndiURL>tcp://localhost:61616</soapjms:jndiURL>
      <soapjms:deliveryMode>PERSISTENT</soapjms:deliveryMode>
      <soapjms:priority>5</soapjms:priority>
      <soapjms:timeToLive>1000</soapjms:timeToLive>
      <wsdl:operation name="greetMe">
         <soap:operation soapAction="test" style="document" />
         <wsdl:input name="greetMeRequest">
            <soap:body use="literal" />
         </wsdl:input>
         <wsdl:output name="greetMeResponse">
            <soap:body use="literal" />
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="JMSGreeterService">
      <soapjms:jndiConnectionFactoryName>
         ConnectionFactory
      </soapjms:jndiConnectionFactoryName>
      <soapjms:jndiInitialContextFactory>
         org.apache.activemq.jndi.ActiveMQInitialContextFactory
      </soapjms:jndiInitialContextFactory>
      <wsdl:port binding="tns:JMSGreeterPortBinding" name="GreeterPort">
         <soap:address location=
            "jms:jndi:dynamicQueues/test.cxf.jmstransport.queue"/>
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>

  • The transport URI (http://www.w3.org/2010/soapjms/) is defined in the <soap:binding>.

  • The jms: URI is defined in the <soap:address>

  • The extension properties are in the <soap:binding>

Define service endpoint or proxy in spring or blueprint

The JAXWS endpoint or proxy can be defined like in the SOAP/HTTP case. Just use a jms: uri like described above.

In CXF 3 it is possible to omit the jndi settings. Just specify an endpoint like this:

Example 42. Endpoint in spring

<bean id="ConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
<jaxws:endpoint id="CustomerService"
    address="jms:queue:test.cxf.jmstransport.queue?timeToLive=1000"
    implementor="com.example.customerservice.impl.CustomerServiceImpl"/>
</jaxws:endpoint>

or a Client like this:

Example 43. Proxy in spring

<bean id="ConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
<jaxws:client id="CustomerService"
    address="jms:queue:test.cxf.jmstransport.queue?timeToLive=1000"
    serviceClass="com.example.customerservice.CustomerService">
</jaxws:client>

The connection factory will be looked up as a bean in the context. By default the name "ConnectionFactory" is assumed but it can be configured using the jndiConnectionFactoryName uri parameter.

Alternatively the connection factory can be set using the ConnectionFactoryFeature.

Publishing a service with the JAVA API

Developers who don't wish to modify the WSDL file can also publish the endpoint information using Java code. For CXF's SOAP over JMS implementation you can write the following:

// You just need to set the address with JMS URI
String address = "jms:jndi:dynamicQueues/test.cxf.jmstransport.queue3"
   + "?jndiInitialContextFactory"
   + "=org.apache.activemq.jndi.ActiveMQInitialContextFactory"
   + "&jndiConnectionFactoryName=ConnectionFactory&jndiURL" 
   + "=tcp://localhost:61500";
Hello implementor = new HelloImpl();
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
svrFactory.setServiceClass(Hello.class);
svrFactory.setAddress(address);
// And specify the transport ID with SOAP over JMS specification
svrFactory.setTransportId(
   JMSSpecConstants.SOAP_JMS_SPECIFICIATION_TRANSPORTID);
svrFactory.setServiceBean(implementor);
svrFactory.create();

NOTE: For tests it can be useful to create an embedded broker like this:

public final void run() {
    try {            
         broker = new BrokerService();
         broker.setPersistent(false);
         broker.setPersistenceAdapter(new MemoryPersistenceAdapter());
         broker.setTmpDataDirectory(new File("./target"));
         broker.setUseJmx(false);
         if (brokerName != null) {
             broker.setBrokerName(brokerName);
         }        broker.addConnector(brokerUrl1);
         broker.start();
    } catch (Exception e) {
         e.printStackTrace();
    }
}
Consume the service with the API

Sample code to consume a SOAP-over-JMS service is as follows:

public void invoke() throws Exception {
   // You just need to set the address with JMS URI
   String address = 
      "jms:jndi:dynamicQueues/test.cxf.jmstransport.queue3"
      + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory"
      + "&jndiConnectionFactoryName=ConnectionFactory"
      + "&jndiURL=tcp://localhost:61500";
   JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
   // And specify the transport ID with SOAP over JMS specification
   factory.setTransportId(
      JMSSpecConstants.SOAP_JMS_SPECIFICIATION_TRANSPORTID);
   factory.setServiceClass(Hello.class);
   factory.setAddress(address);
   Hello client = (Hello)factory.create();
   String reply = client.sayHi(" HI");
   System.out.println(reply);
}

// Alternatively using the JAXWS API with jms details defined in WSDL while avoiding JNDI
SOAPService2 service = new SOAPService2(wsdl, serviceName); // Using the generated service
ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61500");
ConnectionFactoryFeature cff = new ConnectionFactoryFeature(cf);
Greeter greeter = service.getPort(portName, Greeter.class, cff); 
// Connection Factory can be set as a feature in CXF >= 3.0.0

If you specify queue or topic as variant and use cxf >= 3.0.0 then the jndi settings are not necessary.

svrFactory.setAddress("jms:queue:test.cxf.jmstransport.queue?timeToLive=1000");
// For CXF >= 3.0.0
svrFactory.setFeatures(Collections.singletonList(new ConnectionFactoryFeature(cf)));

In this case case the connection factory is supplied using a feature. For CXF 2.x the connection factory can only be supplied using jndi.

Using the JMSConfigFeature

Standard JMS transport configuration in CXF is done by defining a JMSConduit or JMSDestination. There is however an easier configuration option more conformant to Spring dependency injection. Additionally the new configuration offers many more options. For example it is not necessary anymore to use JNDI to resolve the connection factory. Instead it can be defined in the Spring configuration.

The following example configs use the p-namespace from Spring 2.5 but the old Spring bean style is also possible.

Inside a features element the JMSConfigFeature can be defined.

<jaxws:client id="CustomerService"
   xmlns:customer="http://customerservice.example.com/"
   serviceName="customer:CustomerServiceService"
   endpointName="customer:CustomerServiceEndpoint" address="jms://"
   serviceClass="com.example.customerservice.CustomerService">
   <jaxws:features>
      <bean xmlns="http://www.springframework.org/schema/beans"
         class="org.apache.cxf.transport.jms.JMSConfigFeature"
         p:jmsConfig-ref="jmsConfig"/>
   </jaxws:features>
</jaxws:client>

In the above example it references a bean "jmsConfig" where the whole configuration for the JMS transport can be done.

A jaxws Endpoint can be defined in the same way:

<jaxws:endpoint 
   xmlns:customer="http://customerservice.example.com/"
   id="CustomerService" 
   address="jms://"
   serviceName="customer:CustomerServiceService"
   endpointName="customer:CustomerServiceEndpoint"
   implementor="com.example.customerservice.impl.CustomerServiceImpl">
   <jaxws:features>
      <bean class="org.apache.cxf.transport.jms.JMSConfigFeature"
         p:jmsConfig-ref="jmsConfig" />
   </jaxws:features>
</jaxws:endpoint>

The JMSConfiguration bean needs at least a reference to a connection factory and a target destination.

<bean id="jmsConfig" class="org.apache.cxf.transport.jms.JMSConfiguration"
   p:connectionFactory-ref="jmsConnectionFactory"
   p:targetDestination="test.cxf.jmstransport.queue"
/>

If your ConnectionFactory does not cache connections you should wrap it in a Spring SingleConnectionFactory. This is necessary because the JMS Transport creates a new connection for each message and the SingleConnectionFactory is needed to cache this connection.

<bean id="jmsConnectionFactory" 
   class="org.springframework.jms.connection.SingleConnectionFactory">
   <property name="targetConnectionFactory">
      <bean class="org.apache.activemq.ActiveMQConnectionFactory">
         <property name="brokerURL" value="tcp://localhost:61616"/>
      </bean>
   </property>
</bean>
Using JMSConfiguration from Java

To do this from Java, you need to initialize a JMSConfiguration object, then store a reference to it in a JMSConfigFeature, and then add that to the features in the server factory. The code that follows is fragmentary. Note that you can't use query parameters in the endpoint URI that you set in the server factory, all the configuration has to be in the JMSConfiguration object.

public static JMSConfiguration newJMSConfiguration(String taskId, String jmsBrokerUrl) {
        String destinationUri = "jms:queue:" + taskId;
        JMSConfiguration conf = new JMSConfiguration();
        conf.setRequestURI(destinationUri);
        JNDIConfiguration jndiConfig = new JNDIConfiguration();
        JndiTemplate jt = new JndiTemplate();
        Properties env = new Properties();
        env.put(Context.PROVIDER_URL, jmsBrokerUrl); 
        env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
        jt.setEnvironment(env);
        jndiConfig.setJndiConnectionFactoryName("ConnectionFactory");
        jndiConfig.setEnvironment(env);
        conf.setJndiTemplate(jt);
        conf.setTargetDestination("com.basistech.jug." + taskId);
        conf.setJndiConfig(jndiConfig);
        conf.setTimeToLive(0);
        return conf;
}
{
        JMSConfigFeature jmsConfigFeature = new JMSConfigFeature();
        JMSConfiguration jmsConfig = JmsUtils.newJMSConfiguration(taskId, jmsBrokerUrl);
        jmsConfig.setConcurrentConsumers(maxServiceThreads);
        jmsConfig.setMaxConcurrentConsumers(maxServiceThreads);
        jmsConfigFeature.setJmsConfig(jmsConfig);
        svrFactory.getFeatures().add(jmsConfigFeature);
        svrFactory.getFeatures().add(jmsConfigFeature);
 
        server = svrFactory.create();
}
JMSConfiguration options

Name

Description

connectionFactory

Mandatory field. Reference to a bean that defines a jms ConnectionFactory. Remember to wrap the connectionFactory like described above when not using a pooling ConnectionFactory

wrapInSingleConnectionFactory

This option was removed since CXF 3.0.0. Will wrap the connectionFactory with a Spring SingleConnectionFactory, which can improve the performance of the jms transport. Default is true.

reconnectOnException

(deprecated) If wrapping the connectionFactory with a Spring SingleConnectionFactory and reconnectOnException is true, will create a new connection if there is an exception thrown, otherwise will not try to reconnect if the there is an exception thrown. Default is false. From CXF 3.0.0, CXF always reconnect on exceptions

targetDestination

JNDI name or provider specific name of a destination. Example for ActiveMQ: test.cxf.jmstransport.queue

destinationResolver

Reference to a Spring DestinationResolver. This allows to define how destination names are resolved to jms Destinations. By default a DynamicDestinationResolver is used. It resolves destinations using the jms providers features. If you reference a JndiDestinationResolver you can resolve the destination names using JNDI.

transactionManager

Reference to a Spring transaction manager. This allows to take part in JTA Transactions with your webservice. You can also register a spring JMS Transaction Manager to have local transactions.

taskExecutor

This option was removed since CXF 3.0.0. Reference to a Spring TaskExecutor. This is used in listeners to decide how to handle incoming messages. Default is a Spring SimpleAsyncTaskExecutor.

useJms11

This option was removed since CXF 3.0.0. true means JMS 1.1 features are used false means only JMS 1.0.2 features are used. Default is false.

messageIdEnabled

Default is true. This option was removed since CXF 3.0.0.

messageTimestampEnabled

Default is true. This option was removed since CXF 3.0.0.

cacheLevel

This option was removed since CXF 3.0.0. Specify the level of caching that the JMS listener container is allowed to apply. (Default is -1) Please check out the java doc of the org.springframework. jms.listener. DefaultMessageListenerContainer for more information

pubSubNoLocal

If true do not receive your own messages when using topics. Default is false.

receiveTimeout

How many milliseconds to wait for response messages. 0 (default) means wait indefinitely. since CXF 3.0, the default value is changed to 60000 (60 seconds)

explicitQosEnabled

If true, means that QoS parameters are set for each message. (Default is false.)

deliveryMode

NON_PERSISTENT = 1 messages will only be kept in memory

PERSISTENT = 2 (default) messages will be persisted to disk

priority

Priority for the messages. Default is 4. See your JMS provider doc for details.

timeToLive

After this time the message will be discarded by the jms provider. Default is 0.

sessionTransacted

If true, means JMS transactions are used. Default is false. In 2.7.x you will also need to register a JMS Transaction Manager with JMSConfiguration in order for transactions to be enabled.

concurrentConsumers

This option was removed since CXF 3.0.0. Minimum number of concurrent consumers for listener (default is 1).

maxConcurrentConsumers

This option was removed since CXF 3.0.0. Maximum number of concurrent consumers for listener (default 1).

maxConcurrentTasks

This option was removed since CXF 3.0.0. (deprecated) Maximum number of threads that handle the received requests. Default 10.

messageSelector

jms selector to filter incoming messages (allows to share a queue)

subscriptionDurable

Default is false.

durableSubscriptionName

 

messageType

text (default) binary byte

pubSubDomain

false (default) means use queues true means use topics

jmsProviderTibcoEms

True means that the jms provider is Tibco EMS. Default is false. Currently this activates that the principal in the SecurityContext is populated from the header JMS_TIBCO_SENDER. (available from cxf version 2.2.6)

maxSuspendedContinuations

Since CXF 3.0.0, The max suspended continuations that the JMS destination could have, if the current suspended continuations number exceeds the max value, the JMSListenerContainer will be stopped. The default value is -1, which means disable this feature.

reconnectPercentOfMax

Since CXF 3.0.0, If the JMSListenerContainer is stopped due to the current suspended continuation exceeds the max value, the JMSListenerContainer will be restarted when the current suspended continuation below the value of (maxSuspendedContinuations*reconnectPercentOfMax/100). The default value is 70.

createSecurityContext

(Since 2.7.14, 3.0.3) true (default) means create user security context for incoming messages.

propogateExceptions

(Since 2.7.15) 2.7.x only true (default) means that any exceptions occurring while processing the incoming message will be propagated. This setting is only relevant when a transaction manager and sessionTransacted are set.