Author |
Message
|
vams |
Posted: Mon Dec 24, 2007 7:29 am Post subject: How to Disconnect the MQ Connection Handle in a JMS Program |
|
|
Newbie
Joined: 17 Dec 2007 Posts: 6
|
Hello Everyone,
I am using JMS and MQ-Series to communicate with a non-JMS client. I have configured my connection factory on the WebSphere server. I just do the following....
1. Look up the connection factory.
2. Get the connection using the connection factory
3. Get the session
4. Create the producer
5. Put the message in the queue.
6. Close the Producer and assign null to the producer object.
7. Close the Session and assign null to the session object
8. Close the Connection and assign null to the Connection object
I am able to successfully send the message. But, my MQ Admin says that he could see the handle still open, it is not getting disconnected.
I checked most of the documentation regaring JMS and WebSphere MQ Connection Factory settings. I could not find anything related to this one. I assumed that when I clos the connection the handle also should get disconnected, but it is not.
Could anyone let me know if you have any idea?
Thanks,
Vamshi. |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Dec 24, 2007 8:22 am Post subject: Re: How to Disconnect the MQ Connection Handle in a JMS Prog |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
vams wrote: |
I assumed that when I clos the connection the handle also should get disconnected, but it is not. |
This is what you actually want to happen. And what your MQ Admin wants to happen, too.
The connection will stay open as long as the app server is running. When your code runs again, it will reuse the connection.
So that the connection is not being opened and closed constantly. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Dec 24, 2007 8:49 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Read up on connection pooling. Check your WAS settings. Understand what the JNDI setup for JMS means in terms of connection pooling, idle time out, pool purging policies etc...
This is expected behavior for a pooled JMS connection. If you are running a standalone JMS program check what happens when the app closes...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
vams |
Posted: Mon Dec 24, 2007 9:22 am Post subject: |
|
|
Newbie
Joined: 17 Dec 2007 Posts: 6
|
Thanks for your reply; I understand the concept of connection pooling. I guess I need to be more clear about my question..
Instead of MQ Connection Handles I should have said Channels... Sorry about that..
The problem is as follows....
We have many users log into our system and they submit request, when ever they submit a request, a new Channel is created with their User Id. I tested in my development environment, I asked my MQ Admin to set a MAX Active Channels to 2 in the Test environment. So, for the first two users it was fine, for the third User, when I try to submit a request it gave me an exception as follows....
MQJMS2005: failed to create MQQueueManager for '%HOST_NAME%:'
at com.ibm.mq.jms.services.ConfigEnvironment.newException(ConfigEnvironment.java:569)
at com.ibm.mq.jms.MQConnection.createQM(MQConnection.java:2321)
at com.ibm.mq.jms.MQConnection.createQMNonXA(MQConnection.java:1749)
at com.ibm.mq.jms.MQConnection.<init>(MQConnection.java:942)
at com.ibm.mq.jms.MQConnectionFactory.createConnection(MQConnectionFactory.java:3136)
at com.ibm.ejs.jms.JMSManagedConnection.createConnection(JMSManagedConnection.java:1363)
....................
So, in order to put the message in the queue, I have to restart my app server.
Could you please let me know how to clear the channel?
Thanks,
Vamshi. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Dec 24, 2007 2:08 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Shame on you! You really need to read the red book on JMS Topologies.
I know it's a little bit dated but the information is still accurate...
Running an apps server (i.e.) connection pool limited to 2 connections on the MQ side with a default of (10?) connections in the pool... makes absolutely no sense
You really need to come up with a credible test scenario and see how the different pool properties come into play. Remember that IBM optimized the pool using the default properties...
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
vams |
Posted: Wed Dec 26, 2007 11:56 am Post subject: |
|
|
Newbie
Joined: 17 Dec 2007 Posts: 6
|
fjb_saper wrote: |
Shame on you! You really need to read the red book on JMS Topologies.
I know it's a little bit dated but the information is still accurate...
Running an apps server (i.e.) connection pool limited to 2 connections on the MQ side with a default of (10?) connections in the pool... makes absolutely no sense
You really need to come up with a credible test scenario and see how the different pool properties come into play. Remember that IBM optimized the pool using the default properties...
Enjoy  |
I guess you mis-understood me. I haven't limited the connection pool, I have asked the MQ admin to limit the MAX Active Channels to 2 for my testing. And I found something interesting in my testing, when ever I create a connection using the user id of the logged in person, it creates a channel based on that person's User Id and will be re-used only by that person, not by any other user. So, I have decieded to have a global User Id, which creates only one channel and will be re-used for any user who logs into the system and submits a request.
But, I still donno how to close the channel from a JMS program.
Let me iknow if you have some idea.
Thanks,
Vams. |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Dec 26, 2007 12:24 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
vams wrote: |
I guess you mis-understood me. I haven't limited the connection pool, I have asked the MQ admin to limit the MAX Active Channels to 2 for my testing. And I found something interesting in my testing, when ever I create a connection using the user id of the logged in person, it creates a channel based on that person's User Id and will be re-used only by that person, not by any other user. So, I have decieded to have a global User Id, which creates only one channel and will be re-used for any user who logs into the system and submits a request.
But, I still donno how to close the channel from a JMS program.
Let me iknow if you have some idea.
Thanks,
Vams. |
And explain to me how this is going to work:
On the appside you have a default of (10?) connections to the pool (MQ Client)
On the MQ side you have a max active channels set to 2.
So tell me what happens when the app server requests the 3rd connection from the pool??
The whole thing about pooling is that the connection MQ side is not released until the pool is purged. The average # of connections in the pool looks like it is always open in MQ...
Like I said => Read up on App server (J2EE) pooling services ... at this point any pooling litterature would help you along (jdbc or JMS)...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
vams |
Posted: Wed Dec 26, 2007 12:50 pm Post subject: |
|
|
Newbie
Joined: 17 Dec 2007 Posts: 6
|
Thank you very much.
I understand what you mean. On the MQ side we have a MAX Active channels of 2, now I use a global User Id when ever I am creating a connection. So, for the very first user who submits a request the channel is created and thus it is pooled and it will remain open until the app server is down. So, when a second user logs in and submits a request then the same channel will be re-used since I am creating the connection using the global user id and in this way no matter how many users submit the request the same channel will be re-used and thus it won't reach the MAX active channel limit.
Please correct me if I am wrong in any of the above mentioned points.
Thanks,
Vams. |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Dec 26, 2007 12:56 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You can't have fewer MaxActiveConnections than you have connections in your pool.
To be more clear, the app server is going to keep opening new connections at each request for a connection, until the pool is full. Once the pool is full, then it will try to re-use connections.
So if you want MaxActive of 2, then you need to limit your pool to 2.
If you want to limit your pool to 10, then you need to ensure that 10 connections can be made in the first place. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
vams |
Posted: Wed Dec 26, 2007 1:46 pm Post subject: |
|
|
Newbie
Joined: 17 Dec 2007 Posts: 6
|
jefflowrey wrote: |
You can't have fewer MaxActiveConnections than you have connections in your pool.
To be more clear, the app server is going to keep opening new connections at each request for a connection, until the pool is full. Once the pool is full, then it will try to re-use connections.
So if you want MaxActive of 2, then you need to limit your pool to 2.
If you want to limit your pool to 10, then you need to ensure that 10 connections can be made in the first place. |
Thank you. Do you mean that MAX Active Channels on MQ and MaxActiveConnections are one and the same? |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Dec 26, 2007 2:37 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
vams wrote: |
Thank you. Do you mean that MAX Active Channels on MQ and MaxActiveConnections are one and the same? |
No.
I mean you should double-check everything you read on the internet against the documentation and your own experience and knowledge. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
vams |
Posted: Tue Jan 08, 2008 11:42 am Post subject: |
|
|
Newbie
Joined: 17 Dec 2007 Posts: 6
|
Thanks for all your inputs. I resolved the issue . I am using a system id when ever I create a connection insteat of the logged on person user id, so in this case only one channel is created and when ever we put a message in the queue, the same channel is used again and again and will remain open until the app is down. |
|
Back to top |
|
 |
|