Announcement Announcement Module
No announcement yet.
Example of a <jms:jca-listener-container> using JBoss JMS with a custom WorkManager Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Example of a <jms:jca-listener-container> using JBoss JMS with a custom WorkManager

    I know that I had a lot of difficulty putting all of the pieces together in order to wire a jms message listener to Jboss using the <jms:jca-listener-container> leveraging off of a custom WorkManager setup within JBoss. I wanted to share our configuration with the Spring community in hopes that it will help somebody else avoid the same difficulty in the future.

    Spring does provide the rTaskExecutor, which will work fine for you if you intend to use the default JBoss WorkManager name 'WorkManager' that is typically setup during a common JBoss installation. Perhaps in the future, the JBossWorkManagerTaskExecutor will expose some attributes allowing us to specify the custom WorkManager ObjectName (hint, hint )
    However, we wanted a separate WorkManager for a highly used JMS queue, allowing us finer granularity to configure the WorkManager separately for our needs.

    The problem with the JBossWorkManagerTaskExecuter is that it uses the rUtils to return the default WorkManager using the JBossWorkManagerUtils.getWorkManager() method, which is 'hard-coded' to only locate the default JBoss WorkManager named at the JMX ObjectName path: jboss.jca:service=WorkManager.

    There is currently no way to set a different ObjectName and use a different WorkManager.
    To get around this limitation, we have defined our own WorkManager and WorkManagerThreadPool within Jboss, which can be placed in a separate xml file in the server's depoy directory. Here is what our JBoss WorkManager and WorkManagerThreadPool looks like:

    <deployment xmlns="urn:jboss:bean-deployer:2.0">
      <!-- ==================================================================== -->
      <!-- JBossCX setup, for J2EE connector architecture support               -->
      <!-- ==================================================================== -->
      <!-- THREAD POOL -->
      <bean name="MPlusWorkManagerThreadPool" class="org.jboss.util.threadpool.BasicThreadPool">
         <!-- Expose via JMX -->
         <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss.jca:service=MPlusWorkManagerThreadPool", exposedInterface=org.jboss.util.threadpool.BasicThreadPoolMBean.class)</annotation>
         <!-- The name that appears in thread names -->
         <property name="name">MPlusWorkManagerThread</property>
         <!-- The maximum amount of work in the queue -->
         <property name="maximumQueueSize">1024</property>
         <!-- The maximum number of active threads -->
         <property name="maximumPoolSize">100</property>
         <!-- How long to keep threads alive after their last work (default one minute) -->
         <property name="keepAliveTime">60000</property>
      <!-- WORK MANAGER -->
      <bean name="MessageHubWorkManager" class="">
         <!-- Expose via JMX -->
         <!-- The thread pool -->
         <property name="threadPool"><inject bean="MPlusWorkManagerThreadPool"/></property>
         <!-- The xa terminator -->
         <property name="XATerminator"><inject bean="TransactionManager" property="XATerminator"/></property>
    Spring has excellent JMX support and now that you have your custom WorkManager deployed in JBoss, you can easily located the WorkManager via JMX by it's ObjectName. Following, is our Spring configuration, showing the necessary beans defined. Particularly, note the messageHubWorkManager bean and how it is located within the mBeanServer. Finally, the MessageHubListener is simply a Message Driven Pojo (MDP) that implements the javax.jms.MessageListener interface, recieving messages via the onMessage(Message message) method.

    <?xml version="1.0" encoding="UTF-8"?>
    <beans default-autowire="byName"
           xmlns="" xmlns:xsi=""
    	<bean id="mbeanServer" class="" factory-method="locateJBoss"/>
    	<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager">
    		<property name="autodetectTransactionManager" value="true"/>
        	<!--<property name="transactionManagerName" value="java:/TransactionManager"/>-->
      	<tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"/>
    	<bean id="jbossResourceAdapter" class="org.jboss.resource.adapter.jms.JmsResourceAdapter"/>
    	<bean id="messageHubWorkManager" factory-bean="mbeanServer" factory-method="getAttribute">
    			<bean class="" factory-method="getInstance">
    				<constructor-arg value="jboss.jca:service=MessageHubWorkManager" />
    		<constructor-arg value="Instance" />
    	<bean id="messageHubTaskExecuter" class="">
    		<property name="workManager" ref="messageHubWorkManager"/>
    	<bean id="jbossResourceAdapterFactory" class="">
    		<property name="resourceAdapter" ref="jbossResourceAdapter"/>
    		<property name="workManager" ref="messageHubTaskExecuter"/>
    	<bean id="jbossActivationSpecFactory" class="org.springframework.jms.listener.endpoint.StandardJmsActivationSpecFactory">
    		<property name="activationSpecClass" value="org.jboss.resource.adapter.jms.inflow.JmsActivationSpec"/>
    		<property name="defaultProperties">
    				<prop key="sessionTransacted">false</prop>
    				<prop key="minSession">1</prop>
    				<prop key="maxSession">15</prop>
    	<bean id="MessageHubListener" class="com.rbs.envoy.listener.MessageHub"/>
      		resource-adapter="jbossResourceAdapterFactory" activation-spec-factory="jbossActivationSpecFactory"
      		concurrency="5-5" acknowledge="auto">
        	<jms:listener destination="rbs.envoy.MessageHubQueue" ref="MessageHubListener"/>
    Good luck and I hope this proves helpful to somebody else!