Results 1 to 4 of 4

Thread: JMSTemplate as class variable

  1. #1
    Join Date
    Nov 2007
    Posts
    13

    Default 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. #2
    Join Date
    Jan 2008
    Location
    San Diego
    Posts
    780

    Default

    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>

  3. #3
    Join Date
    Nov 2007
    Posts
    13

    Default

    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 at 01:03 PM. Reason: typo

  4. #4
    Join Date
    Jan 2008
    Location
    San Diego
    Posts
    780

    Default

    Quote 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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •