cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache CXF Documentation > Using the JMSConfigFeature
Date Wed, 11 Jan 2012 21:45:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CXF20DOC&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/CXF20DOC/Using+the+JMSConfigFeature">Using
the JMSConfigFeature</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~bimargulies@gmail.com">Benson
Margulies</a>
    </h4>
        <div id="versionComment">
        <b>Comment:</b>
        add Jave example.<br />
    </div>
        <br/>
                         <h4>Changes (3)</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" >A jaxws Endpoint can be defined in
the same way: <br>{code} <br></td></tr>
            <tr><td class="diff-unchanged" >&lt;jaxws:endpoint <br></td></tr>
            <tr><td class="diff-unchanged" >	xmlns:customer=&quot;http://customerservice.example.com/&quot;
<br></td></tr>
            <tr><td class="diff-unchanged" >	id=&quot;CustomerService&quot;
<br></td></tr>
            <tr><td class="diff-unchanged" >	address=&quot;jms://&quot;
<br>	serviceName=&quot;customer:CustomerServiceService&quot; <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >&lt;/bean&gt; <br>{code}
<br></td></tr>
            <tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">JMSConfiguration
options: <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">
<br>h2. Using JMSConfiguration from Java <br> <br>To do this from Java,
you need to initialize a JMSConfiguration object, then store a reference to it in  <br>a
JMSConfigFeature, and then add that to the features in the server factory. The code that follows
<br>is fragmentary. Note that you can&#39;t use query parameters in the endpoint
URI that you set in the  <br>server factory, all the configuration has to be in the
JMSConfiguration object. <br> <br>{code} <br> public static JMSConfiguration
newJMSConfiguration(String taskId, String jmsBrokerUrl) { <br>        String destinationUri
= &quot;jms:queue:&quot; + taskId; <br>        JMSConfiguration conf = new JMSConfiguration();
<br>        conf.setRequestURI(destinationUri); <br>        JNDIConfiguration
jndiConfig = new JNDIConfiguration(); <br>        JndiTemplate jt = new JndiTemplate();
<br>        Properties env = new Properties(); <br>        env.put(Context.PROVIDER_URL,
jmsBrokerUrl);  <br>        env.put(Context.INITIAL_CONTEXT_FACTORY, &quot;org.apache.activemq.jndi.ActiveMQInitialContextFactory&quot;);
<br>        jt.setEnvironment(env); <br>        jndiConfig.setJndiConnectionFactoryName(&quot;ConnectionFactory&quot;);
<br>        jndiConfig.setEnvironment(env); <br>        conf.setJndiTemplate(jt);
<br>        conf.setTargetDestination(&quot;com.basistech.jug.&quot; + taskId);
<br>        conf.setJndiConfig(jndiConfig); <br>        conf.setTimeToLive(0);
<br>        return conf; <br>    } <br>    { <br>        JMSConfigFeature
jmsConfigFeature = new JMSConfigFeature(); <br>        JMSConfiguration jmsConfig =
JmsUtils.newJMSConfiguration(taskId, jmsBrokerUrl); <br>        jmsConfig.setConcurrentConsumers(maxServiceThreads);
<br>        jmsConfig.setMaxConcurrentConsumers(maxServiceThreads); <br>     
  jmsConfigFeature.setJmsConfig(jmsConfig); <br>        svrFactory.getFeatures().add(jmsConfigFeature);
<br>        svrFactory.getFeatures().add(jmsConfigFeature); <br> <br>  
     server = svrFactory.create(); <br>    } <br>{code} <br> <br>
<br>h2. JMSConfiguration options <br></td></tr>
            <tr><td class="diff-unchanged" >|| Name || Description \\ || <br>|
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
\\ | <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| messageTimestampEnabled | Default
is true. | <br>| cacheLevel | Specify the level of caching that the JMS listener container
is allowed to apply. \\ <br></td></tr>
            <tr><td class="diff-changed-lines" >Please check out the java doc
of the org.springframework.jms.listenerDefaultMessageListenerContainer for more information.
 Default is <span class="diff-changed-words"><span class="diff-added-chars"style="background-color:
#dfd;">\</span>-1.</span> | <br></td></tr>
            <tr><td class="diff-unchanged" >| pubSubNoLocal | If true, do not
receive your own messages when using topics.  Default is false. \\ | <br>| receiveTimeout
| How many milliseconds to wait for response messages. 0 (default) means wait indefinitely.
\\ | <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| sessionTransacted | If true, means
JMS transactions are used. (Default is false). \\ | <br>| concurrentConsumers | Minimum
number of concurrent consumers for listener (default 1). \\ | <br></td></tr>
            <tr><td class="diff-unchanged" >| maxConcurrentConsumers | Maximum
number of concurrent consumers for listener (default 1). | <br></td></tr>
            <tr><td class="diff-unchanged" >| maxConcurrentTasks | Maximum number
of threads that handle the received requests (Default 10). | <br>| messageSelector \\
| jms selector to filter incoming messages (allows to share a queue) \\ | <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| pubSubDomain \\ | false (default)
means use queues \\ <br>true means use topics \\ | <br></td></tr>
            <tr><td class="diff-unchanged" >| 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) | <br></td></tr>
            <tr><td class="diff-unchanged" >| useMessageIDAsCorrelationID | If
true, specifies JMS broker will use the message ID to correlate messages. By default (false)
a CXF client will set a generated correlation id instead | <br>\\ <br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <p>In older CXF version the JMS transport is configured by defining a JMSConduit
or JMSDestination. Starting with CXF 2.0.9 and 2.1.3 the JMS transport includes an easier
configuration option that is more conformant to the spring dependency injection. Additionally
the new configuration has much 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 config.</p>

<p>The following example configs use the <a href="http://static.springframework.org/spring/docs/2.5.x/reference/beans.html"
class="external-link" rel="nofollow">p-namespace</a> from spring 2.5 but the old
spring bean style is also possible.</p>

<p>Inside a features element the JMSConfigFeature can be defined.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
 &lt;jaxws:client id=<span class="code-quote">"CustomerService"</span>
	xmlns:customer=<span class="code-quote">"http:<span class="code-comment">//customerservice.example.com/"</span>
</span>	serviceName=<span class="code-quote">"customer:CustomerServiceService"</span>
	endpointName=<span class="code-quote">"customer:CustomerServiceEndpoint"</span>
address=<span class="code-quote">"jms:<span class="code-comment">//"</span>
</span>	serviceClass=<span class="code-quote">"com.example.customerservice.CustomerService"</span>&gt;
	&lt;jaxws:features&gt;
		&lt;bean xmlns=<span class="code-quote">"http:<span class="code-comment">//www.springframework.org/schema/beans"</span>
</span>			class=<span class="code-quote">"org.apache.cxf.transport.jms.JMSConfigFeature"</span>
			p:jmsConfig-ref=<span class="code-quote">"jmsConfig"</span>/&gt;
	&lt;/jaxws:features&gt;
&lt;/jaxws:client&gt;
</pre>
</div></div>
<p>In the above example it references a bean "jmsConfig" where the whole configuration
for the JMS transport can be done.</p>

<p>A jaxws Endpoint can be defined in the same way:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
&lt;jaxws:endpoint
	xmlns:customer=<span class="code-quote">"http:<span class="code-comment">//customerservice.example.com/"</span>
</span>	id=<span class="code-quote">"CustomerService"</span>
	address=<span class="code-quote">"jms:<span class="code-comment">//"</span>
</span>	serviceName=<span class="code-quote">"customer:CustomerServiceService"</span>
	endpointName=<span class="code-quote">"customer:CustomerServiceEndpoint"</span>
	implementor=<span class="code-quote">"com.example.customerservice.impl.CustomerServiceImpl"</span>&gt;
	&lt;jaxws:features&gt;
		&lt;bean class=<span class="code-quote">"org.apache.cxf.transport.jms.JMSConfigFeature"</span>
			p:jmsConfig-ref=<span class="code-quote">"jmsConfig"</span> /&gt;
	&lt;/jaxws:features&gt;
&lt;/jaxws:endpoint&gt;
</pre>
</div></div>


<p>The JMSConfiguration bean needs at least a reference to a conncection factory and
a target destination.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
 &lt;bean id=<span class="code-quote">"jmsConfig"</span> class=<span class="code-quote">"org.apache.cxf.transport.jms.JMSConfiguration"</span>
	p:connectionFactory-ref=<span class="code-quote">"jmsConnectionFactory"</span>
	p:targetDestination=<span class="code-quote">"test.cxf.jmstransport.queue"</span>
/&gt;
</pre>
</div></div>
<p>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.</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
class="code-quote">"org.springframework.jms.connection.SingleConnectionFactory"</span>&gt;
	&lt;property name=<span class="code-quote">"targetConnectionFactory"</span>&gt;
		&lt;bean class=<span class="code-quote">"org.apache.activemq.ActiveMQConnectionFactory"</span>&gt;
			&lt;property name=<span class="code-quote">"brokerURL"</span> value=<span
class="code-quote">"tcp:<span class="code-comment">//localhost:61616"</span>
/&gt;
</span>		&lt;/bean&gt;
	&lt;/property&gt;
&lt;/bean&gt;
</pre>
</div></div>

<h2><a name="UsingtheJMSConfigFeature-UsingJMSConfigurationfromJava"></a>Using
JMSConfiguration from Java</h2>

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

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
 <span class="code-keyword">public</span> <span class="code-keyword">static</span>
JMSConfiguration newJMSConfiguration(<span class="code-object">String</span> taskId,
<span class="code-object">String</span> jmsBrokerUrl) {
        <span class="code-object">String</span> destinationUri = <span class="code-quote">"jms:queue:"</span>
+ taskId;
        JMSConfiguration conf = <span class="code-keyword">new</span> JMSConfiguration();
        conf.setRequestURI(destinationUri);
        JNDIConfiguration jndiConfig = <span class="code-keyword">new</span> JNDIConfiguration();
        JndiTemplate jt = <span class="code-keyword">new</span> JndiTemplate();
        Properties env = <span class="code-keyword">new</span> Properties();
        env.put(Context.PROVIDER_URL, jmsBrokerUrl); 
        env.put(Context.INITIAL_CONTEXT_FACTORY, <span class="code-quote">"org.apache.activemq.jndi.ActiveMQInitialContextFactory"</span>);
        jt.setEnvironment(env);
        jndiConfig.setJndiConnectionFactoryName(<span class="code-quote">"ConnectionFactory"</span>);
        jndiConfig.setEnvironment(env);
        conf.setJndiTemplate(jt);
        conf.setTargetDestination(<span class="code-quote">"com.basistech.jug."</span>
+ taskId);
        conf.setJndiConfig(jndiConfig);
        conf.setTimeToLive(0);
        <span class="code-keyword">return</span> conf;
    }
    {
        JMSConfigFeature jmsConfigFeature = <span class="code-keyword">new</span>
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();
    }
</pre>
</div></div>


<h2><a name="UsingtheJMSConfigFeature-JMSConfigurationoptions"></a>JMSConfiguration
options</h2>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Name </th>
<th class='confluenceTh'> Description <br class="atl-forced-newline" /> </th>
</tr>
<tr>
<td class='confluenceTd'> connectionFactory </td>
<td class='confluenceTd'> 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
<br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> wrapInSingleConnectionFactory </td>
<td class='confluenceTd'> Will wrap the connectionFactory with a Spring SingleConnectionFactory,
which can improve the performance of the jms transport.  Default is true. </td>
</tr>
<tr>
<td class='confluenceTd'> reconnectOnException </td>
<td class='confluenceTd'> 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.
</td>
</tr>
<tr>
<td class='confluenceTd'> targetDestination </td>
<td class='confluenceTd'> JNDI name or provider specific name of a destination. Example
for ActiveMQ: <br class="atl-forced-newline" />
test.cxf.jmstransport.queue </td>
</tr>
<tr>
<td class='confluenceTd'> replyDestination </td>
<td class='confluenceTd'> <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> destinationResolver </td>
<td class='confluenceTd'> 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. <br class="atl-forced-newline" />
</td>
</tr>
<tr>
<td class='confluenceTd'> transactionManager <br class="atl-forced-newline" />
</td>
<td class='confluenceTd'> Reference to a spring transaction manager. This allows to
take part in JTA Transactions with your webservice. <br class="atl-forced-newline" />
</td>
</tr>
<tr>
<td class='confluenceTd'> taskExecutor </td>
<td class='confluenceTd'> Reference to a spring TaskExecutor. This is used in listeners
to decide how to handle incoming messages. Default is a spring SimpleAsyncTaskExecutor. <br
class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> useJms11 </td>
<td class='confluenceTd'> true means JMS 1.1 features are used <br class="atl-forced-newline"
/>
false means only JMS 1.0.2 features are used.  Default is false. <br class="atl-forced-newline"
/> </td>
</tr>
<tr>
<td class='confluenceTd'> messageIdEnabled </td>
<td class='confluenceTd'> Default is true. </td>
</tr>
<tr>
<td class='confluenceTd'> messageTimestampEnabled </td>
<td class='confluenceTd'> Default is true. </td>
</tr>
<tr>
<td class='confluenceTd'> cacheLevel </td>
<td class='confluenceTd'> Specify the level of caching that the JMS listener container
is allowed to apply. <br class="atl-forced-newline" />
Please check out the java doc of the org.springframework.jms.listenerDefaultMessageListenerContainer
for more information.  Default is &#45;1. <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> pubSubNoLocal </td>
<td class='confluenceTd'> If true, do not receive your own messages when using topics.
 Default is false. <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> receiveTimeout </td>
<td class='confluenceTd'> How many milliseconds to wait for response messages. 0 (default)
means wait indefinitely. <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> explicitQosEnabled </td>
<td class='confluenceTd'> If true, means that QoS parameters are set for each message.
 Default is false. </td>
</tr>
<tr>
<td class='confluenceTd'> deliveryMode </td>
<td class='confluenceTd'> NON_PERSISTENT = 1 (default) messages will be kept only in
memory <br class="atl-forced-newline" />
<br class="atl-forced-newline" />
PERSISTENT = 2&nbsp;&nbsp;&nbsp; messages will be persisted to disk <br class="atl-forced-newline"
/> </td>
</tr>
<tr>
<td class='confluenceTd'> priority </td>
<td class='confluenceTd'> Priority for the messages. Default is 4. See your JMS provider
doc for details <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> timeToLive </td>
<td class='confluenceTd'> After this time the message will be discarded by the jms provider
(default 0). <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> sessionTransacted </td>
<td class='confluenceTd'> If true, means JMS transactions are used. (Default is false).
<br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> concurrentConsumers </td>
<td class='confluenceTd'> Minimum number of concurrent consumers for listener (default
1). <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> maxConcurrentConsumers </td>
<td class='confluenceTd'> Maximum number of concurrent consumers for listener (default
1). </td>
</tr>
<tr>
<td class='confluenceTd'> maxConcurrentTasks </td>
<td class='confluenceTd'> Maximum number of threads that handle the received requests
(Default 10). </td>
</tr>
<tr>
<td class='confluenceTd'> messageSelector <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> jms selector to filter incoming messages (allows to share
a queue) <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> subscriptionDurable <br class="atl-forced-newline" />
</td>
<td class='confluenceTd'> Default false. </td>
</tr>
<tr>
<td class='confluenceTd'> durableSubscriptionName <br class="atl-forced-newline"
/> </td>
<td class='confluenceTd'>&nbsp;</td>
</tr>
<tr>
<td class='confluenceTd'> messageType <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> text (default) <br class="atl-forced-newline" />
binary <br class="atl-forced-newline" />
byte <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> pubSubDomain <br class="atl-forced-newline" /> </td>
<td class='confluenceTd'> false (default) means use queues <br class="atl-forced-newline"
/>
true means use topics <br class="atl-forced-newline" /> </td>
</tr>
<tr>
<td class='confluenceTd'> jmsProviderTibcoEms </td>
<td class='confluenceTd'> 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) </td>
</tr>
<tr>
<td class='confluenceTd'> useMessageIDAsCorrelationID </td>
<td class='confluenceTd'> If true, specifies JMS broker will use the message ID to correlate
messages. By default (false) a CXF client will set a generated correlation id instead </td>
</tr>
</tbody></table>
</div>

<p><br class="atl-forced-newline" /></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/CXF20DOC/Using+the+JMSConfigFeature">View
Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=100809&revisedVersion=12&originalVersion=11">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CXF20DOC/Using+the+JMSConfigFeature?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message