ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ API Support » Creating Dynamic Queue in c#

Post new topic  Reply to topic
 Creating Dynamic Queue in c# « View previous topic :: View next topic » 
Author Message
paul1492
PostPosted: Mon May 03, 2021 1:30 pm    Post subject: Creating Dynamic Queue in c# Reply with quote

Newbie

Joined: 03 May 2021
Posts: 5

How do I read from a model queue in C#?

I'm writing to a ABC.QA.T00.FTP.TRIGGER.REQUEST queue. Then, I need to do the following:
Quote:
2) Open/specify ABC.QM.REPLY.0001 and ABC.* for your (dynamic queue) responses from MQ and
the mainframe. This dynamic queue will contain the same MQCOMM fields as you previous sent, but
will now contain the mainframe return codes on whether your request was successfully processed or not.


I'm doing this to put a message on the ABC.QA.T00.FTP.TRIGGER.REQUEST by doing:
Code:
                _mqQMgr.AccessQueue(_mQConfigurationSendQueue, MQC.MQOO_OUTPUT).Put(message, options);


Then, I'm having troubles reading from the dyanmic queue. I've tried this:
Code:
               _mqQMgr.AccessQueue(
_mQConfigurationReplyQueue, MQC.MQOO_OUTPUT | MQC.MQOO_BROWSE | MQC.MQOO_FAIL_IF_QUIESCING,
                    _mQConfiguration.QueueMgr,
_mQConfiguration.ReplyQueue, "").Get(message, options);


Where _mQConfigurationReplyQueue is "ABC.QM.REPLY.0001".

What am I doing wrong?
Back to top
View user's profile Send private message
bruce2359
PostPosted: Mon May 03, 2021 2:16 pm    Post subject: Re: Creating Dynamic Queue Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9394
Location: US: west coast, almost. Otherwise, enroute.

paul1492 wrote:
Then, I'm having troubles reading from the dyanmic queue.

Please be more precise. What troubles are you having? What ReasonCode from what MQ call?
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
paul1492
PostPosted: Mon May 03, 2021 2:56 pm    Post subject: Re: Creating Dynamic Queue Reply with quote

Newbie

Joined: 03 May 2021
Posts: 5

bruce2359 wrote:
paul1492 wrote:
Then, I'm having troubles reading from the dyanmic queue.

Please be more precise. What troubles are you having? What ReasonCode from what MQ call?
I am getting the exception MQRC_OBJECT_ALREADY_EXISTS when I try to read the Model Queue.
Back to top
View user's profile Send private message
bruce2359
PostPosted: Mon May 03, 2021 3:25 pm    Post subject: Re: Creating Dynamic Queue in c# Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9394
Location: US: west coast, almost. Otherwise, enroute.

paul1492 wrote:
How do I read from a model queue in C#?

Then, I'm having troubles reading from the dyanmic queue. I've tried this:
Code:
               _mqQMgr.AccessQueue(
_mQConfigurationReplyQueue, MQC.MQOO_OUTPUT | MQC.MQOO_BROWSE | MQC.MQOO_FAIL_IF_QUIESCING,
                    _mQConfiguration.QueueMgr,
_mQConfiguration.ReplyQueue, "").Get(message, options);


Where _mQConfigurationReplyQueue is "ABC.QM.REPLY.0001".

What am I doing wrong?

To open a queue for input, specify MQC.MQOO_INPUT
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
paul1492
PostPosted: Mon May 03, 2021 3:43 pm    Post subject: Re: Creating Dynamic Queue in c# Reply with quote

Newbie

Joined: 03 May 2021
Posts: 5

bruce2359 wrote:

To open a queue for input, specify MQC.MQOO_INPUT
Compiler error, no such thing as MQC.MQOO_INPUT. Changed it to MQC.MQOO_INPUT_EXCLUSIVE:
Code:
mqQMgr.AccessQueue(
_mQConfigurationReplyQueue, MQC.MQOO_INPUT_EXCLUSIVE | MQC.MQOO_BROWSE | MQC.MQOO_FAIL_IF_QUIESCING,
                    _mQConfiguration.QueueMgr,
_mQConfiguration.ReplyQueue, "").Get(message, options)


and get the same error
Back to top
View user's profile Send private message
gbaddeley
PostPosted: Mon May 03, 2021 4:03 pm    Post subject: Re: Creating Dynamic Queue Reply with quote

Jedi

Joined: 25 Mar 2003
Posts: 2492
Location: Melbourne, Australia

paul1492 wrote:
bruce2359 wrote:
paul1492 wrote:
Then, I'm having troubles reading from the dyanmic queue.

Please be more precise. What troubles are you having? What ReasonCode from what MQ call?
I am getting the exception MQRC_OBJECT_ALREADY_EXISTS when I try to read the Model Queue.

Check your logic. Read the IBM doc on model queues and dynamic queues - https://www.ibm.com/docs/en/ibm-mq/9.2?topic=queues-dynamic-model

You can't get or put messages to a model queue.
A model queue is a template object that is used by MQ to create a local queue. The local queue can be temporary dynamic or permanent dynamic.
_________________
Glenn
Back to top
View user's profile Send private message
paul1492
PostPosted: Mon May 03, 2021 5:20 pm    Post subject: Re: Creating Dynamic Queue Reply with quote

Newbie

Joined: 03 May 2021
Posts: 5

gbaddeley wrote:

Check your logic. Read the IBM doc on model queues and dynamic queues - https://www.ibm.com/docs/en/ibm-mq/9.2?topic=queues-dynamic-model

You can't get or put messages to a model queue.
A model queue is a template object that is used by MQ to create a local queue. The local queue can be temporary dynamic or permanent dynamic.

I've been looking at the documentation for weeks and getting nowhere. Hence my post looking for an example.

The documentation refers to MQOPEN, MQPUT, MQGET, but the IBMMQDotNetClient 9.2 I'm using has Get/Put in MQQueue and AccessQueue MQQueueManager but not these functions. In short, the documentation doesn't match the API I'm using.

The only place I see a reference in the API to a dynamic queue is in this prototype, but I'm not sure how to call it:

Code:
        public MQQueue AccessQueue(string queueName, int openOptions, string queueManagerName, string dynamicQueueName, string alternateUserId);

I'm being told by my MQ group that when I send my request on the ABC.QA.T00.FTP.TRIGGER.REQUEST queue, I also need to provide the dynamic queue (ABC.QM.REPLY.0001) in which I'm expecting my response.

How do I do this with the C# API? I'm not seeing how from the documentation. I appreciate any help I can get. Thanks in advance.[/code]
Back to top
View user's profile Send private message
bruce2359
PostPosted: Mon May 03, 2021 6:16 pm    Post subject: Re: Creating Dynamic Queue Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9394
Location: US: west coast, almost. Otherwise, enroute.

The code snipped you provided is how a dynamic queue is created.

Code:
        public MQQueue AccessQueue(string queueName, int openOptions, string queueManagerName, string dynamicQueueName, string alternateUserId);

queueName - is the name of a QModel definition (like SYSTEM.DEFAULT.MODEL.QUEUE). This definition is used as a template for the queue that will be created.
dynamicQueueName - is the naming-rule for the dynamically created queue as a result of a successful open. Valid rule examples:
* tells the qmgr to create a queue named AMQ.uniquebytestring
BOB.* tells the qmgr to name the queue BOB.uniquebytestring
BOB.REPLY.QUEUE tells the qmgr to use that exact name.

After successful open, the dynamicQueueName field will contain the resolved dynamic queue name based on the naming rule your specified. This is the name that you must copy into the MQMD ReplyToQueueName field of the request message. The consuming app will use this name to put the reply message.
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
bruce2359
PostPosted: Tue May 04, 2021 8:39 am    Post subject: Reply with quote

Poobah

Joined: 05 Jan 2008
Posts: 9394
Location: US: west coast, almost. Otherwise, enroute.

IBM offers sample programs in a variety of languages here https://www.ibm.com/docs/en/ibm-mq/7.5?topic=programs-sample-distributed-platforms
Search the page for keywords like 'request sample' or 'reply sample'
_________________
I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live.
Back to top
View user's profile Send private message
gbaddeley
PostPosted: Tue May 04, 2021 8:14 pm    Post subject: Reply with quote

Jedi

Joined: 25 Mar 2003
Posts: 2492
Location: Melbourne, Australia

Note that the app is responsible for deleting the dynamic queue after it is no longer required (eg. the reply messages have been consumed).
The IBM docs describe the various methods.

A "must read" - https://colinpaice.blog/2019/06/02/should-i-use-dynamic-queues-probably-not-for-high-volume-production-work/
_________________
Glenn
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Wed May 05, 2021 11:52 am    Post subject: Re: Creating Dynamic Queue Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3252
Location: London, ON Canada

paul1492 wrote:
I've been looking at the documentation for weeks and getting nowhere.

The MQ Knowledge Center has good documentation but it also makes the assumption you have a good understanding of IBM MQ. Hence, the docs are confusing for beginners. That is why IBM created the web sites: IBM Developer Learn MQ, IBM Developer MQ Essentials and IBM Developer MQ Tutorials.

Ok. Back to your issue when opening a queue. Here is the documentation for MQQueueManager.NET class. Now scroll down to AccessQueue method (there are 2 of them - look at the 2nd one).

The biggest mistake newbie IBM MQ programmers make is that they assume MQ will automatically close and disconnect from the queue manager for them. This is a VERY bad assumption. MQ does NOT close a queue/topic or disconnect from the queue manager for the application.

I see you are using the fluent API style for opening the queue.

Code:
_mqQMgr.AccessQueue( _mQConfigurationReplyQueue,
                     MQC.MQOO_OUTPUT | MQC.MQOO_BROWSE | MQC.MQOO_FAIL_IF_QUIESCING,
                     _mQConfiguration.QueueMgr,
                     _mQConfiguration.ReplyQueue,
                     "").Get(message, options);

How did you close the queue?

paul1492 wrote:
Where _mQConfigurationReplyQueue is "ABC.QM.REPLY.0001".
I am getting the exception MQRC_OBJECT_ALREADY_EXISTS when I try to read the Model Queue.

Did you call the AccessQueue method in a loop? Was queue "ABC.QM.REPLY.0001" already defined? See below, I think that is the model queue. A model queue is a template for creating another queue (i.e. temporary or permanent). You cannot get/put messages to a model queue.

The AccessQueue method is:
Code:
public MQQueue AccessQueue(string queueName,
                           int openOptions,
                           string queueManagerName,
                           string dynamicQueueName,
                           string alternateUserId);


As Bruce said above, the "queueName" field needs to be a model queue and the "dynamicQueueName" needs to contain what you want as a prefix IF it contains an asterisk ('*') or a specific queue name if it does not contains an asterisk ('*'). Note: You can simply use an asterisk ('*') and the queue manager will generate a temporary dynamic queue name as AMQ.################ (16 alphanumeric chars) or CSQ.################ for z/OS.

Also, the queueManagerName field and the alternateUserId field should be set to null.

Here is how your call should be coded:

Code:
MQQueue _tempDynQueue = _mqQMgr.AccessQueue( _mQConfigurationReplyQueue,
                     MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING;,
                     null,
                     _mQConfiguration.ReplyQueue,
                     null);


paul1492 wrote:
2) Open/specify ABC.QM.REPLY.0001 and ABC.* for your (dynamic queue) responses from MQ and the mainframe.

To me, that sounds like your model queue is ABC.QM.REPLY.0001 and clearly it says to use ABC.* as your dynamic queue name.
i.e.
Code:
_mQConfigurationReplyQueue = "ABC.QM.REPLY.0001";
_mQConfiguration.ReplyQueue =  "ABC.*";


Also, I bet the mainframe application expects the MQMD ReplyToQueueManagerName and ReplyToQueueName fields to have the corresponding values. Otherwise, how is the mainframe application know what queue and queue manager to put the reply message to? i.e. Request/Reply scenario.

To know what the temporary dynamic queue name is, use the Name field of the MQQueue class. i.e. _tempDynQueue.Name then set the values in your Request message.
i.e.
Code:
MQMessage requestMsg = new MQMessage();
requestMsg.Format = MQC.MQFMT_STRING;
requestMsg.MessageType = MQC.MQMT_REQUEST;
requestMsg.MessageId = MQC.MQMI_NONE;
requestMsg.CorrelationId = MQC.MQCI_NONE;
requestMsg.ReplyToQueueManagerName = {YourQMgrName};
requestMsg.ReplyToQueueName = _tempDynQueue.Name;


I've posted a lot of C# .NET MQ code on StackOverflow. Here is MQTest02.cs which gets a message from a queue: https://stackoverflow.com/questions/48802320/websheremq-net-client-get-multiple-message-one-get/48814342#48814342

Regards,
Roger Lacroix
Capitalware Inc.
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
paul1492
PostPosted: Wed May 26, 2021 3:28 am    Post subject: Re: Creating Dynamic Queue Reply with quote

Newbie

Joined: 03 May 2021
Posts: 5

Thanks for your post Roger. That helped out a lot. I think I got it working.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ API Support » Creating Dynamic Queue in c#
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.