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 IndexIBM MQ Java / JMSMultiple Consumers on Queue

Post new topicReply to topic
Multiple Consumers on Queue View previous topic :: View next topic
Author Message
kadoe
PostPosted: Thu Jun 29, 2017 6:37 am Post subject: Multiple Consumers on Queue Reply with quote

Newbie

Joined: 29 Jun 2017
Posts: 2

Hi all,
first of all let me describe my current scenario. I'm trying to setup a Queue, with multiple Clients which are collecting the messages. They are intended to work as consumers, so one message gets processed only by one Client.

My current code (This tool will be just installed multiple times):

Code:

MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
cf.setPort(port);
cf.setHostName(machine);
cf.setQueueManager(qmgr);
cf.setChannel(channel);
cf.setTransportType(WMQConstants.WMQ_CM_CLIENT);

MQQueueConnection conn = (MQQueueConnection)cf.createQueueConnection();

MQQueueSession session = (MQQueueSession)conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Queue mqQueue = session.createQueue(queue);

MQQueue q = (MQQueue) mqQueue;
MQQueueReceiver receiver = (MQQueueReceiver)session.createReceiver(mqQueue);
receiver.setMessageListener(new MListener());
conn.start();


The Problem is, that the above code (The first client connecting) will set an exclusive read on the queue. Therefore no other client will be able to connect any more:
Code:
com.ibm.mq.MQException: JMSCMQ0001: WebSphere MQ call failed with compcode '2' ('MQCC_FAILED') reason '2042' ('MQRC_OBJECT_IN_USE')


The queue itself has as "default input option": shared.


As far as I know IBM MQ offers some properties for the client:
MQOO_INPUT_SHARED & MQOO_INPUT_EXCLUSIVE

Unfortunately it's not clear to me how to set. Adding them to the Queue name directly (?key1=val1&key2=val2) does not work.

Does somebody have a hint?

Many thanks in advance
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Jun 29, 2017 7:54 am Post subject: Reply with quote

Grand Poobah

Joined: 18 Nov 2003
Posts: 19149
Location: LI,NY

When creating your destination (queue) you need to use the URI form and also pass the constant for the desired value... example:

Code:
queuestr="queue:///MY.QUEUE.NAME?targetClient=1&ccsid=1208"
MQQueue myq = (MQQueue)session.createQueue(queuestr);

Best way to find the correct attribute is to set them all on the MQQueue and then print the Destination reference....

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
kadoe
PostPosted: Thu Jun 29, 2017 8:46 am Post subject: Reply with quote

Newbie

Joined: 29 Jun 2017
Posts: 2

Many thanks for your hint. Unfortunately it seems the MQQueue object does not have the proper attribute to set nor any other plausible one.

So I'm still a bit confused where the problem is and if the current code base even supports this.
Back to top
View user's profile Send private message
PaulClarke
PostPosted: Thu Jun 29, 2017 2:34 pm Post subject: Reply with quote

Sentinel

Joined: 17 Nov 2005
Posts: 814
Location: New Zealand

I'm afraid I don't know how to set MQOO_INPUT_SHARED & MQOO_INPUT_EXCLUSIVE in this language either. However, it is worth checking that the queue is indeed shareable. What is the SHARE or NOSHARE value of the queue in question ?

Cheers,

Paul.
_________________
Paul Clarke
MQGem Software
www.mqgem.com
Back to top
View user's profile Send private message Visit poster's website
tczielke
PostPosted: Fri Jun 30, 2017 12:36 pm Post subject: Reply with quote

Yatiri

Joined: 08 Jul 2010
Posts: 623
Location: Illinois, USA

I didn't see a way either in the IBM MQ JMS extensions code to set the open options, but perhaps I missed it.

I did trace a sample IBM MQ JMS extensions program that comes with MQ called SimpleWMQJMSPTP. It's logic is very similar to what you are doing:
Code:

    // Variables
    MQQueueConnection connection = null;
    MQQueueSession session = null;
    MQQueue queue = null;
    MQQueueSender sender = null;
    MQQueueReceiver receiver = null;

    try {
      // Create a connection factory
      MQQueueConnectionFactory cf = new MQQueueConnectionFactory();

      // Set the properties
      cf.setHostName("localhost");
      cf.setPort(1414);
      cf.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
      cf.setQueueManager("QM1");
      cf.setChannel("CHL1");

      // Create JMS objects
      connection = (MQQueueConnection) cf.createQueueConnection();
      session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      queue = (MQQueue) session.createQueue("queue:///Q1");
      sender = (MQQueueSender) session.createSender(queue);
      receiver = (MQQueueReceiver) session.createReceiver(queue);


and I see the following being specified when the queue is opened for the consumer:

Code:

MQOO.Options= (MQLONG)      : 8233
   Options=MQOO_INPUT_AS_Q_DEF
   Options=MQOO_BROWSE
   Options=MQOO_INQUIRE
   Options=MQOO_FAIL_IF_QUIESCING


The queue was opened with "MQOO_INPUT_AS_Q_DEF", so the exclusive/shared option should be based on how your queue defined the DefInputOpenOption queue attribute.
_________________
MQ administrator since 2010.
Back to top
View user's profile Send private message
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexIBM MQ Java / JMSMultiple Consumers on Queue
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.