Announcement Announcement Module
Collapse
No announcement yet.
JMSTemplate as class variable Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JMSTemplate as class variable

    I struggled with this for a while and figured out the solution, but I don't really understand why. I wanted to know if anyone had any insite into this.

    I was obtaining an instance of a jmstemplate from the application context and storing it as a class variable. I would then use that reference to to call convertAndSend()on it. However we noticed that the convertAndSend() was causing null pointer exceptions after some time. I think the underlying connection pooling was causing this issue.

    I fixed this by removeing the class level variable and always calling getBean()on the connection factory to get the JMS template and it seems to work all the time. I thought the getbean() was just returning a reference, which I was storing in my class level variable. However it seems that it is also doing some kind of connection cleanup. Does anyone have any idea of what is happening under the covers?

    (I am using websphere 6.0 and connected to Websphere MQ with connection pooling enabled) All the JNDI settings are setup inside the container properlyly
    Thanks in advance.

  • #2
    We inject jms template into quite a few objects and we don't have any issues. One thing you probably need to do is wire it up with the singleconnectionfactory and make sure that it is set to reconnect on exception, e.g.:

    Code:
        <bean id="queueConnectionFactoryBean" class="org.springframework.jms.connection.SingleConnectionFactory" destroy-method="destroy">
          <constructor-arg>
            <bean class="com.atomikos.jms.QueueConnectionFactoryBean" init-method="init">
              <property name="xaQueueConnectionFactory" ref="queueConnectionFactoryXa"/>
            </bean>
          </constructor-arg>
          <property name="reconnectOnException"  value="true"></property>
      </bean>
    
      <bean id="jmsTemplateXa" class="org.springframework.jms.core.JmsTemplate">
        <property name="connectionFactory"><ref local="queueConnectionFactoryBean" /></property>
        <property name="destinationResolver"><ref local="tibcoDestinationResolver" /></property>
        <property name="receiveTimeout" value="-1"/>
        <!-- Atomikos needs this to be set to work correctly -->
        <property name="sessionTransacted" value="true"/>
      </bean>

    Comment


    • #3
      Thanks for the input. I'm using the jndiObjectFactory bean to grab the connection factory from JNDI, is there a way to setup reconnect in this case?
      Last edited by pshah; Oct 15th, 2008, 01:03 PM. Reason: typo

      Comment


      • #4
        Originally posted by pshah View Post
        Thanks for the input. I'm using the jndiObjectFactory bean to grab the connection factory from JNDI, is there a way to setup reconnect in this case?
        Wrap your JNDI connection factory in the single connection factory as I am doing above for my tibco connection factory.

        Comment

        Working...
        X