New Session created every time message is sent using JMSTemplate

I am using JMSTemplate to send message to the external system. There is limit on number of connections allowed to the external system.
I am sending the message one by one though loop.
I have seen the JMSTemplate class definition and the method doSend close the connection every time. Though my each operation to send message take individual connection and number of connection reached to the upper limit set by the external system.

I am using SingleConnectionFactory to get the connection. Below are spinet of my configuration file and code.

Spring Version: 2.0.2

Spring Configuration File:
=====================
<!-- connection factory for local queue -->
      <bean id="jmsConnectionFactory"
            class="org.springframework.jms.connection.SingleConnectionFactory">
            <property name="targetConnectionFactory">                                          
                        <ref bean="queueConnectionFactory"/>
            </property>
            <!--  <property name="username" value="" />
            <property name="password" value="" />-->
      </bean>

      <!-- Actual connection factory setting. Need to load the information from jms.properties -->
      <bean id="queueConnectionFactory" class="com.ibm.mq.jms.MQConnectionFactory">
            <property name="transportType" value="${jms.transportType}" />
            <property name="hostName" value="${jms.hostName}" />
            <property name="port" value="${jms.port}" />
            <property name="channel" value="${jms.channel}" />
            <property name="SSLCipherSuite" value="${jms.ssl.cipherSuite}" />
            <property name="SSLSocketFactory" ref="sslSocketFactoryBean" />            
      </bean>

<!-- JMS Templates -->
    <bean id="JmsTemplate" class="org.springframework.jms.core.JmsTemplate"  abstract="true">
        <property name="connectionFactory" ref="jmsConnectionFactory" />
        <property name="sessionTransacted" value="true" />
    </bean>


Java Code:
========
jmsTemplate.convertAndSend((Object) msg, new MessagePostProcessor() {

                  public Message postProcessMessage(Message message)
                              throws JMSException {
                        m[0] = message;
                        return message;
                  }
            });

pvashaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Plk_In_EECommented:
Hi,
whats the application server you are using if use web logic. this can be done as per below,

Creating a JMS Template
To define the JMS template configuration attributes for destinations, use the JMS —> Templates node.
1.      Expand the JMS —> Templates node. The JMS Templates table displays in the right pane showing all the templates defined in the domain.
2.      Click the Configure a new JMS Template text link. A dialog displays in the right pane showing the tabs associated with configuring a new template.
3.      On the Configuration General tab, define the general configuration attributes for the JMS template.
•      Name of the JMS template. This name must be unique within a WebLogic Server instance, cluster, or domain. For more information, see JMS Resource Naming Rules for Domain Interoperability.
•      Destination keys used to define the sort order for messages arriving on destinations created from this JMS template.
For more information about the topic general attributes, see JMS Template --> Configuration --> General.
4.      Click Create to create a template instance with the name you specified in the Name field. The new instance is added under the Templates node in the left pane.
5.      On the Configuration Thresholds & Quotas tab, define the following upper and lower message/byte threshold and maximum quota attributes for the destinations created from this JMS template:
•      Specify the maximum bytes or message quota that can be stored in a destination.
•      Specify the upper threshold value that trigger events based on the number of bytes or messages stored in a
•      destination. Events include message paging, message flow control, and system log messages.
•      Specify the lower threshold value that trigger events based on the number of bytes or messages stored in a destination. Events include message paging, message flow control, and system log messages.
•      Indicate whether bytes or messages paging is enabled on a destination for temporarily swapping messages out from memory to a paging store when a destination's message load reaches a specified bytes/messages threshold.
•      Specify the maximum size of a message that will be accepted from message producers on a destination. The size includes the message body, any user-defined properties, and the user-defined JMS header fields: JMSCorrelationID and JMSType.
For more information about the JMS template Thresholds & Quota attributes, see JMS Template --> Configuration --> Thresholds & Quotas.
6.      On the Configuration Override tab, define the message attributes that can override those specified by a message producer for destinations created from this JMS template, including the priority, time-to-live, time-to-deliver, and delivery mode.
For more information about the JMS template override attributes, see JMS Template --> Configuration --> Override.
7.       On the Configuration Redelivery tab, define the message redelivery attributes for destinations created from this JMS template, including redelivery delay override, redelivery limit, and error destination.
For more information about the JMS template redelivery attributes, see JMS Template --> Configuration --> Redelivery.
8.        On the Configuration Expiration Policy tab, define the message expiration policy logging properties to use when expired messages are encountered on destinations created from this JMS template.
For more information about the JMS template expiration policy attributes, see JMS Template --> Configuration --> Expiration Policy.
•  Click Apply to save any changes you made on these tabs.
0
pvashaAuthor Commented:
We are using Apache Tomcat container.

Connection factory is created through the configuration file. That connection factory we are using for the sending/receiving messages.

I forgot to paste the listener configuration in first comment. We are using DefaultMessageListener for receiving the messages.

<!-- Abstract Message Listener Container -->
    <bean id="abstractMessageListenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer" abstract="true">          
        <property name="connectionFactory" ref="jmsConnectionFactory" />      
    </bean>

    <!-- Incoming Swift Message -->
      <bean id="InQueueMessageListenerContainer" parent="abstractMessageListenerContainer">
            <property name="destination" ref="swiftInQueue" />
            <property name="messageListener">
                  <bean class="org.springframework.jms.listener.adapter.MessageListenerAdapter">
                        <constructor-arg index="0">
                              <bean class="comm.agent.InProcessor" />
                        </constructor-arg>
                  </bean>
            </property>
      </bean>
0
regevhaCommented:
The queueConnectionFactory indicates you are sending JMS messages to IBM WebSphere MQ. It is not clear which MQ JMS client version you are using.

I recommend to enable MQ JMS tracing and attach the trace output for our investigation - http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/topic/com.ibm.mq.csqzaw.doc/jm10770_.htm
You may also refer to IBM Redbook on WebSphere MQ V7.0 features and enhancements (section 7.7) : http://www.redbooks.ibm.com/redbooks/pdfs/sg247583.pdf

Use the following Java properties when running your client application:
com.ibm.msg.client.commonservices.trace.startup=true
com.ibm.msg.client.config.location=file:/D:/mydir/myjms.config
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

pvashaAuthor Commented:
We are using a shared service, kind of an ESB, which in turn uses IBM Websphere MQ v 7. Out here on one queue manager multiple applications have their own Queues with their dedicated channels.
The problem I am facing is that I have two listeners which listen to different queues, Queue A and Queue B, which share the same connection factory. For messages received in Queue A, i need to post the incoming message to another queue, Queue C, and then do some processing. When my application starts, 2 connections are created for the two listeners. When a message is received in Queue A, the same needs to be posted in Queue C and then do some processing. The problem we are facing is that when we post the message to Queue C, the connection still remains open and does not get close. So after some time it reaches the max number of open connections permitted and then no further messages are allowed to be put to Queue C. I want to know how can I share the connection or session between the two queues. If I cannot do that then how can I ensure that the connection which is created for posting the message to Queue C is closed after the posting is complete. I will try to get the logs as mentioned by regevha.
0
pvashaAuthor Commented:
We resolved the issue using the org.springframework.jms.listener.SessionAwareMessageListener for the incoming queues. For outgoing messages, we are ensuring that we are closing the session (returning it to the pool) after every run as the messages are sent out in a Batch.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pvashaAuthor Commented:
I thank all the experts who tried to help us out for finding the solution.
0
pvashaAuthor Commented:
Experts pointed out to resources which could help us out. Also we were unable to provide more details to experts for them to provide us with concrete solution. In the meanwhile we came up with the solution within our own team.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.