1

I read the messages from one queue to another queue. However my correlation ids are not preserved.

If the correlation id is "ABC12345" for a message in the import queue, when i put it into the export queue, the value of the correlation id is different.

How do i keep the same correlation id between the 2 queues and always have a unique message id?

Get:

mqQueue.Get(mqMsg);
string messageID = Convert.ToString(mqMsg.MessageId);
string correlationID = Convert.ToString(mqMsg.CorrelationId);

If for example if the correlation id is "000123456789", then after read, while putting it back , the value gets changed for the same message.

Put:

 mqMsg.CorrelationId = System.Text.Encoding.UTF8.GetBytes(correlationID);
 mqQueue.Put(mqMsg, mqPutMsgOpts);

I am using MQ PUT and GET options via MQ.NET classes.

JoshMc
  • 10,239
  • 2
  • 19
  • 38
Sharpeye500
  • 8,775
  • 25
  • 95
  • 143
  • Please define `Different` it would help if you would display and or tell us what the difference is.. – MethodMan Apr 02 '13 at 01:34
  • look at this link maybe it will help since we can't see your existing code.. http://www.codeproject.com/Articles/12198/IBM-WebSphere-MQ-with-C-GUI-application-that-is-bo#cs_C%2523%20passing%20Id%27s%20to%20MQ – MethodMan Apr 02 '13 at 01:36
  • Can show the snippet that reads message from import queue and puts the same message to export queue? – Shashi Apr 02 '13 at 10:21
  • I have added the code snippet, please share your thoughts. – Sharpeye500 Apr 02 '13 at 16:53
  • @Shashi - How to generate unique message id #s in the send message? – Sharpeye500 Apr 02 '13 at 18:11

2 Answers2

1

The code snippet below preserves the correlation id when I put message to another queue. In my sample I do the following:

1) Put a message to importQ with unique correlation ID.
2) Get that message from importQ.
3) Put the received message to exportQ

    public static void preserveCorreLid()
    {
        Hashtable mqProps = new Hashtable();
        MQQueueManager qm = null;
        String strCorrelId = "00123456789";

        try
        {
            mqProps.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
            mqProps.Add(MQC.CHANNEL_PROPERTY, "NET.CLIENT.CHL");
            mqProps.Add(MQC.HOST_NAME_PROPERTY, "localhost");
            mqProps.Add(MQC.PORT_PROPERTY, 2099);

            qm = new MQQueueManager("QM", mqProps);

            MQQueue importQ = qm.AccessQueue("IMPORTQ", MQC.MQOO_INPUT_SHARED |MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING );

            MQMessage mqPutMsg = new MQMessage();
            mqPutMsg.WriteString("This is an import message");
            mqPutMsg.CorrelationId = System.Text.Encoding.UTF8.GetBytes(strCorrelId);
            MQPutMessageOptions mqpmo = new MQPutMessageOptions();
            importQ.Put(mqPutMsg,mqpmo);

            MQMessage respMsg = new MQMessage();
            MQGetMessageOptions gmo = new MQGetMessageOptions();
            gmo.WaitInterval = 3000;
            gmo.Options = MQC.MQGMO_WAIT;

            try
            {
                importQ.Get(respMsg, gmo);
            }
            catch (MQException ex)
            {
                Console.Write(ex);

                Console.WriteLine("Queue Name : " + importQ.Name + ":");
            }
            importQ.Close();

            MQQueue exportQ = qm.AccessQueue("EXPORTQ", MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING);
            exportQ.Put(respMsg);
            exportQ.Close();
            qm.Disconnect();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
    }
Shashi
  • 14,980
  • 2
  • 33
  • 52
  • I am able to pass correlation id, what i was asking is whether mq client auto generates a unique message id for every message being sent? – Sharpeye500 Apr 03 '13 at 17:40
  • You have to use MQPMO_NEW_CORREL_ID option to tell MQ to generate a correlation id automatically. – Shashi Apr 04 '13 at 04:40
0

This line of code gets me the correlation id

  correlationID = System.Text.Encoding.UTF8.GetString(mqMsg.CorrelationId);
Sharpeye500
  • 8,775
  • 25
  • 95
  • 143