Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Inside a features element the JMSConfigFeature can be defined.

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

...

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

Code Block
 <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.

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

...

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.

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

...