RSS 2.0
Sign In
# Saturday, 05 April 2008

Does WebSphere MQ library for .NET support a connection pool? This is the question, which ask many .NET developers who deal with IBM WebSphere MQ and write multithread applications. The answer to this question unfortunately is NO… The .NET version supports only individual connection types.

I have compared two MQ libraries Java's and one for .NET, and I’ve found that most of the classes have the same declarations except one crucial for me difference. As opposed to .NET, the Java MQ library provides several classes implementing MQ connection pooling. There is nothing similar in .NET library.

There are few common workarounds for this annoying restriction. One of such workarounds (is recommended by IBM in their “MQ using .NET”) is to keep open one MQ connection per thread. Unfortunately such approach is not working for ASP.NET applications (including web services).

The good news is that starting from service pack 5 for MQ 5.3, and of course for MQ 6.xx they are supporting sharing MQ connections in blocked mode:

“The implementation of WebSphere MQ .NET ensures that, for a given connection (MQQueueManager object instance), all access to the target WebSphere MQ queue manager is synchronized. The default behavior is that a thread that wants to issue a call to a queue manager is blocked until all other calls in progress for that connection are complete.”

This allows creating an MQ connection (pay attention that MQQueueManager object is a wrapper for MQ connection) in one thread and exclusive use it in another thread without side-effects caused by multithreading.

Taking in account this feature, I’ve created a simple MQ connection pool. It’s ease in use. The main class MQPoolManager has only two static methods:

public static MQQueueManager Get(string QueueManagerName, string ChannelName, string ConnectionName);

and

public static void Release(ref MQQueueManager queueManager);

The method Get returns MQ queue manager (either existing from pool or newly created one), and Release returns it to the connection pool. Internally the logic of MQPoolManager tracks expired connections and do some finalizations, if need.

So, you may use one MQ connection pool per application domain without additional efforts and big changes in existing applications.

By the way, this approach has allowed us to optimize performance of MQ part considerably in one of ours projects.

Later on...

To clarify using of MQPoolManager I've decided to show here following code snippet:

  MQQueueManager queueManager = 
MQPoolManager.Get(QueueManagerName, ChannelName, ConnectionName); try { // TODO: some work with MQ here } finally { MQPoolManager.Release(ref queueManager); } // at this point the queueManager is null

Saturday, 05 April 2008 20:55:57 UTC  #    Comments [7] -
Tips and tricks
Thursday, 20 November 2008 09:13:14 UTC
I dont see how the Function Release is getting called. Also if the application is dealing with many queues under the same queue manager, I dont think this code can be used
RamanaKumar Alapati
Thursday, 20 November 2008 13:05:29 UTC
Hello RamanaKumar Alapati,

1) In order to return a MQQueueManager instance to the pool YOU have to call MQPoolManager.Release() method and pass an instance there. The pool manager will take care of that queue manager instance. This method is used instead of MQQueueManager.disconnect() method, which destroys a MQQueueManager instance.

2) An application may use as many queue managers and queues as it needs. It's a mistake to think that there is any limitattion on number of queues under a queue manager or number of queue manager instances in the pool.

Thanks for feedback.
Arthur Nesterovsky
Friday, 05 December 2008 08:28:46 UTC
Hi Arthur Nesterovsky
Thanks for the explanation on the usage of Release.
Regarding the usage of many queues(which are under the same queue manager), what I really looking forward to is "Is it possible to create the MQ Pool on the basis of MQ Manager, MQ Queue?". This way the performance can even be bettered as we can get the right connection(MQ Manager+MQ Queue) from the pool . If you have any sample code for the same please post the same. Thanks for the reply.
RamanaKumar Alapati
Friday, 05 December 2008 19:25:02 UTC
Hi,
what about the fact that a connection could be invalid in the pool. Is it possible to validate it before returning it to the user of the connection pool?
Karol Deland
Friday, 05 December 2008 21:18:35 UTC
Hi Karol Deland,

Indeed, the pool sometime may contain invalid connections, but please take a look at the MQPoolManager implementation. The MQ connections pool contains instances of PoolItem class. The QueueManager property of this class does some invalidations, so the end user either gets a live connection or null, if there is no a valid connection.

Thanks for feedback.
Arthur Nesterovsky
Friday, 05 December 2008 23:44:58 UTC
Hi RamanaKumar Alapati,

No, I don't have a sample for "MQ Manager + MQ Queue" approach, and moreover, I think this is not a good solution. Such approach requires using a queue manager instance per a queue instance, whereas the current implementation allows to use with the same queue manager instance several queues instances simultaneously.
Arthur Nesterovsky
Friday, 10 September 2010 13:59:17 UTC
Hi,
I'm using .Net 4.0 Task Parallel Library to throw multiple request/response message at WebSphereMQ.
Apparently the second Get hangs until timeout.
Without multithread it works ok.
Any help is welcome.
Lombaers Philippe
Comments are closed.
Archive
<2024 December>
SunMonTueWedThuFriSat
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234
Statistics
Total Posts: 387
This Year: 3
This Month: 0
This Week: 0
Comments: 2178
Locations of visitors to this page
Disclaimer
The opinions expressed herein are our own personal opinions and do not represent our employer's view in anyway.

© 2024, Nesterovsky bros
All Content © 2024, Nesterovsky bros
DasBlog theme 'Business' created by Christoph De Baene (delarou)