How to get information about a message received from a queue

I am new to IBM MQ. Using the following code, I can easily send a message to the queue and receive this message.

public void QueuePut()
{
        queue = queueManager.AccessQueue("Q1", MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
        MQMessage message = new MQMessage();
        message.WriteString("stackoverflow");

        MQPutMessageOptions putMessageOptions = new MQPutMessageOptions(); 
        putMessageOptions.Options += MQC.MQPMO_ASYNC_RESPONSE;

        queue.Put(message, putMessageOptions);
}


public void QueueGet()
{

        queue = queueManager.AccessQueue("Q2", MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);
        MQMessage gotMessage = new MQMessage();

        queue.Get(gotMessage);

        string str = message.ReadString(gotMessage.MessageLength);
}

      

You can easily see that I am writing the message "Q1" and reading it from "Q2" since Q1 is an alias

Now I want to get information about the message I received in the QueueGet function. What I want to know is that gotMessage comes from "Q1" even though I read it in "Q2".

+3


source to share


3 answers


BaseQueueName

will point to the real queue to which the alias queue belongs. In this case, the queue that is opened to receive queues is the most real one. Hence, BaseQueueName

it will not indicate anything.

It is not correct to use MQC.MQCA_BASE_Q_NAME

when opening a queue as it is not an option to open a queue. All queue opening options start with MQOO_

.

You can use the PCF classes to query the alias queue and find the base queue name. But at the moment I don't know if there is a way to find the base queue alias.

Edit:



Alias queue

not really a queue like Local queue

. As the name suggests, this is a different name for the local queue. It will not contain any messages. When the application opens the Alias ​​queue, the queue manager resolves it to the actual queue.

Aliasing helps

1) To hide the queue / topic it points to. This way applications are not affected by queue / theme changes.

2) Provide different levels of authority for applications. One application can push but not receive, while another application can receive but not queue.

+1


source


On return from the MQGET

structure, it MQGMO

has a field that indicates the name of the local queue from which the message was received, that is, the underlying queue, even if you got it from an alias.

Check out the field MQGMO

ResolvedQName

here

The aforementioned C-Procedural MQ API, to translate this into the OO classes you are using, this means you need to use queue.Get

with two parameters, the second is an instance MQGetMessageOptions

.



See "Using .NET> Message Handling"

Then you can access the field ResolvedQName

in MQGetMessageOptions

.

+1


source


Here is the related MQ property from the IBM documentation :

MQ_Property_From_IBM_Documentation

I can't test this because I don't have all the required components to test this, but I believe this should work:

string queueName = "Q2";
queue = queueManager.AccessQueue(queueName, MQC.MQOO_OUTPUT 
                                       + MQC.MQOO_INQUIRE
                                       + MQC.MQCA_BASE_Q_NAME
                                       + MQC.MQOO_FAIL_IF_QUIESCING);

Console.WriteLine("QueueName=" + queueName 
                  + " BaseQueueName=" + mqQueue.BaseQueueName);

if (queueName.Equals(mqQueue.BaseQueueName))
   Console.WriteLine("Message is coming from a different underlying queue");

      

0


source







All Articles