4

I'm trying to read off messages from a websphere mq queue and dump it in another queue.

Below is the code i have to do it

private void transferMessages()
{
    MQQueueManager sqmgr = connectToQueueManager(S_SERVER_NAME, S_QMGR_NAME, S_PORT_NUMBER, S_CHANNEL_NAME);
    MQQueueManager dqmgr = connectToQueueManager(D_SERVER_NAME, D_QMGR_NAME, D_PORT_NUMBER, D_CHANNEL_NAME);
    if (sqmgr != null && dqmgr != null)
    {
        MQQueue sq = openSourceQueueToGet(sqmgr, S_QUEUE_NAME);
        MQQueue dq = openDestQueueToPut(dqmgr, D_QUEUE_NAME);
        if (sq != null && dq != null)
        {
            setPutMessageOptions();
            setGetMessageOptions();
            processMessages(sqmgr, sq, dqmgr, dq);
        }
    }
}

And I'm calling the above method in a for loop and creating separate threads as below.

int NO_OF_THREADS = 5;
Thread[] ts = new Thread[NO_OF_THREADS];
for (int i = 0; i < NO_OF_THREADS; i++)
{ 
    ts[i] = new Thread(() => transferMessages());
    ts[i].Start();        
}

As you see, I'm making a fresh connection to the queue manager in the transferMessages method. Not sure for some reason, the program makes only one connection to MQ.

The custom method to connect to the queue manager is below..

    private MQQueueManager connectToQueueManager(string MQServerName, string MQQueueManagerName, string MQPortNumber, string MQChannel)
    {
        try
        {
            mqErrorString = "";
            MQQueueManager qmgr;
            Hashtable mqProps = new Hashtable();
            mqProps.Add(MQC.HOST_NAME_PROPERTY, MQServerName);
            mqProps.Add(MQC.CHANNEL_PROPERTY, MQChannel);
            mqProps.Add(MQC.PORT_PROPERTY, Convert.ToInt32(MQPortNumber));
            mqProps.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
            qmgr = new MQQueueManager(MQQueueManagerName, mqProps);
            return qmgr;
        }
        catch (MQException mqex)
        {
            //catch and log MQException here
            return null;
        }
    }

Any advise what am i missing?

ᄂ ᄀ
  • 5,669
  • 6
  • 43
  • 57
  • 1
    Something in the chain is serializing the connect calls. Either in your own connectToQueueManager or in the MQ API. You shouldn't use Threads anyway (look at Tasks and ThreadPool). – H H Jul 11 '15 at 10:15
  • @Henk, I've added the custom connectToQueueManager method code. It has nothing much other than creating a connection to the queue manager by having a HashTable to store the connection properties, and using the same with standard MQ APIs to make a connection to MQ queue manager.. Also, as per your advise, i'll check out Tasks or ThreadPools.. I'll update once i find a fix for the issue i'm facing. Thanks. – Vinay Sathyanarayana Jul 11 '15 at 10:21
  • If your application connects the same set of queue managers, then why not connect and open queues only once! – Shashi Jul 11 '15 at 10:31
  • @Shashi, I want to read off messages from the queue at a quicker rate by making multiple connections to the queue manager and by opening multiple readers-writers to the queues. – Vinay Sathyanarayana Jul 11 '15 at 10:45

1 Answers1

1

That is because of Shared Conversation (SHARECNV) feature of MQ where multiple connections to queue manager from one application share the same socket. This value is a negotiated between client and queue manager while establishing a connection. By default 10 connections will be shared over a socket.

You can increase the number of threads in your application to 11, then you can see a second connection being opened. More details on SHARECNV are here.

UPDATE Channel status when running 6 threads each for put and get. Note I am connecting to the same queue manager (test purpose only). SHARECNV is set to 10.

     2 : dis chstatus(MY.SVRCONN)
AMQ8417: Display Channel Status details.
   CHANNEL(MY.SVRCONN)                     CHLTYPE(SVRCONN)
   CONNAME(127.0.0.1)                      CURRENT
   STATUS(RUNNING)                         SUBSTATE(RECEIVE)
AMQ8417: Display Channel Status details.
   CHANNEL(MY.SVRCONN)                     CHLTYPE(SVRCONN)
   CONNAME(127.0.0.1)                      CURRENT
   STATUS(RUNNING)                         SUBSTATE(RECEIVE)

When running 5 threads each.

 3 : dis chstatus(MY.SVRCONN)
AMQ8417: Display Channel Status details.
   CHANNEL(MY.SVRCONN)                     CHLTYPE(SVRCONN)
   CONNAME(127.0.0.1)                      CURRENT
   STATUS(RUNNING)                         SUBSTATE(RECEIVE)
Shashi
  • 14,980
  • 2
  • 33
  • 52
  • Before posting my question here, I've tried by changing it to 0 and other different values. No luck. – Vinay Sathyanarayana Jul 11 '15 at 10:43
  • Ran your test program and posted results as UPDATE. – Shashi Jul 11 '15 at 11:15
  • Can you please post the queue manager connections before and after you start the program? (DIS QMSTATUS CONNS) and also the queue IPPROCS and OPPROCS? Are you saying that the above code works, and i've to make some change in MQ configs /queue manager configs? PS : I ran another program which was successfully making multiple connections to a queue manager. When i run it now, it is failing. Trying to test with other queue managers. Thank you. – Vinay Sathyanarayana Jul 11 '15 at 11:24
  • Modified your code to just make connections, removed code that was opening the queues. So don't have IPPROCS/OPPROCS details. Number of connections before and after starting the program are 22 and 32 respectively. – Shashi Jul 11 '15 at 11:33
  • Thanks Shashi. Then i've something going wrong... Let me debug.. Nothing in the logs too.. :( – Vinay Sathyanarayana Jul 11 '15 at 11:46
  • 1
    Remember about using the DISPLAY CONN command which will show you the number of connections made to the queue manager, even if they are shared over one channel (and thus DISPLAY CHSTATUS will only show one connection). This will help you figure out if you are making multiple connections or not. – Morag Hughson Jul 11 '15 at 21:45
  • @Morag, I'm doing a DIS QMSTATUS CONNS should show increased connections if the thread starts on, as per my previous command above.. But no luck. The number of CONNS increase by 1 though I start 10 threads.. – Vinay Sathyanarayana Jul 14 '15 at 16:25
  • And does the DISPLAY CONN command show? Does it back that up? – Morag Hughson Jul 15 '15 at 14:34