3

I'm new in IBM MQ. Using the following code I can easily put a message in a queue and get that 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 I'm writing a message to 'Q1' and reading it from 'Q2' since Q1 is alias queue

Now, the thing I want is to get information about the message that I got in the QueueGet function. What I want to know is that gotMessage comes from 'Q1' even If I'm reading it in 'Q2'.

JoshMc
  • 10,239
  • 2
  • 19
  • 38
brtb
  • 2,201
  • 6
  • 34
  • 53
  • It does not sound right to me, how can you read the message from the Q2 queue if it was put in queue Q1? – Alioza Jun 10 '15 at 19:19
  • @Alioza Q1 is an alias of Q2. – Shashi Jun 11 '15 at 03:30
  • Do you still have a need to find out what original queue name was put to? I found a work around that allows this by pointing the alias queues to topic objects and then subscribing the destination queue to the topic strings. This will add properties in the MQMD that can indicate the original queue name put to. Let me know if you want me to write the details up as an answer? – JoshMc May 09 '17 at 22:13

3 Answers3

1

The BaseQueueName will point to the real queue an alias queue refers to. In this case the queue being opened to get queues is the real queue itself. Hence BaseQueueName will not point to anything.

It's not right to use MQC.MQCA_BASE_Q_NAME while opening a queue as it's not a queue open option. All queue open options begin with MQOO_.

You can use PCF classes to query an alias queue and find it's base queue name. But at the moment I am unaware if there is a way to find the alias(es) of a base queue.

Edit:

Alias queue is not really a queue like the Local queue. As the name suggests, it's another name for a local queue. It will not hold any messages. When an application opens an Alias queue, the queue manager resolves it to actual queue.

Aliasing helps

1) To hide queue/topic it is pointing to. This way applications are unaffected by any change to queue/topic.

2) Provide different level of authority to applications. One application can put but not get while another application can get but not put to the same queue.

Shashi
  • 14,980
  • 2
  • 33
  • 52
  • let s say we found aliases of a base queue, how can we know that the message comes from a certain alias or from another alias. That is Q1 base Q2 and Q3 aliases. i read Q1 and i got message and also i know aliases of Q1. So then? how can we know the message comes from Q2. What if it comes from Q3 – brtb Jun 11 '15 at 07:31
  • so you mean that i cant do what i want – brtb Jun 11 '15 at 14:08
1

Upon return from an MQGET, the MQGMO structure has a field which tells you the name of the local queue the message was retrieved from, i.e. the base queue, even if you got it from an alias.

Read about MQGMO field ResolvedQName here

The above is the 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 one being an instance of the MQGetMessageOptions.

See "Using .NET > Handling Messages"

You should then be able to access the ResolvedQName field in the MQGetMessageOptions.

Morag Hughson
  • 7,255
  • 15
  • 44
  • there is message and i m putting it to 'Q1' and i m reading it from 'Q2'. In your opinion we should read MQGetMessageOptions on QueueGet function and it gives that Q2's ResolvedQName is again Q2. But if we were reading Q1 then its ResolvedQName = 'Q2' so your solution was true. That is, Q2 is local queue while Q1 is alias queue – brtb Jun 12 '15 at 07:10
  • It will always give you the local q at the base of the alias in the ResolvedQName field. If that queue name doesn't match the one you're getting from then you can imply something from that. – Morag Hughson Jun 12 '15 at 09:05
0

Here is the related MQ property from the IBM documentation:

MQ_Property_From_IBM_Documentation

I'm unable to 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");
Consult Yarla
  • 1,150
  • 10
  • 22
  • It's not right to use MQC.MQCA_BASE_Q_NAME while opening a queue as it's not a queue open option. All queue open options begin with MQOO_ . The above code will not work. – Shashi Jun 11 '15 at 03:17