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 » [Solved] message group problem using base java api on NT

Post new topic  Reply to topic
 [Solved] message group problem using base java api on NT « View previous topic :: View next topic » 
Author Message
desinus
PostPosted: Wed Dec 11, 2002 6:27 am    Post subject: [Solved] message group problem using base java api on NT Reply with quote

Newbie

Joined: 10 Dec 2002
Posts: 6
Location: US

Hello all,

I tried message grouping using base java api however, I don't seem to be getting any message back using the get api. I am not sure if I am doing the put right which could result in the problem with the get. This is how I do it,
--------- PUT ---------------
int PUT_OPEN_OPTIONS = MQC.MQOO_OUTPUT | MQC.MQOO_SET;
qMgr = new MQQueueManager(qManager);
MQQueue sendQueue = qMgr.accessQueue(sendQ, PUT_OPEN_OPTIONS,
null, null, null);
MQMessage msg = new MQMessage();
pmo.options = MQC.MQPMO_LOGICAL_ORDER;
msg.messageFlags = MQC.MQMF_MSG_IN_GROUP;
msg.writeString("1");
msg.messageFlags = MQC.MQMF_MSG_LAST_IN_GROUP;
msg.writeString("2");
sendQueue.put(msg, pmo);
sendQueue.close();
qMgr.disconnect();
------------------- GET ----------------
int GET_OPEN_OPTIONS = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_INQUIRE | MQC.MQOO_SET;
qMgr = new MQQueueManager(qManager);
MQQueue getQueue = qMgr.accessQueue(receiveQ, GET_OPEN_OPTIONS, null, null, null);
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_LOGICAL_ORDER | MQC.MQGMO_ALL_MSGS_AVAILABLE;
gmo.waitInterval = 1000;
getQueue.get(msg, gmo, size);
msgText = msg.readString(msg.getTotalMessageLength());
getQueue.close();
qMgr.disconnect();
--------------------------------------------------------------------------
On printing the messages The message id and the group id is the same however, the message sequence number does not increment i.e. stays at 1 for each of the messages in the group.
I am not sure what I do wrong. I would appreciate it if someone could tell me the problem in my code. Thanks in advance,

D
Back to top
View user's profile Send private message
bduncan
PostPosted: Wed Dec 11, 2002 11:08 am    Post subject: Reply with quote

Padawan

Joined: 11 Apr 2001
Posts: 1554
Location: Silicon Valley

I'm not sure if I'm reading this wrong, or perhaps you only posted a subset of your overall code, the following lines look highly suspect:
Quote:
msg.messageFlags = MQC.MQMF_MSG_IN_GROUP;
msg.writeString("1");
msg.messageFlags = MQC.MQMF_MSG_LAST_IN_GROUP;
msg.writeString("2");
sendQueue.put(msg, pmo);
sendQueue.close();
qMgr.disconnect();

Looks to me like you are using the same object (msg) and the second time you are calling messageFlags and writeString on it, you are only actually MQPUTing one message and the original flags and message content have been overwritten...
_________________
Brandon Duncan
IBM Certified MQSeries Specialist
MQSeries.net forum moderator
Back to top
View user's profile Send private message Visit poster's website AIM Address
desinus
PostPosted: Wed Dec 11, 2002 12:32 pm    Post subject: age group problem using base java api on Windows NT Reply with quote

Newbie

Joined: 10 Dec 2002
Posts: 6
Location: US

Here is the complete code where scenario1(), scenario2(), scenario3() and scenario4() show the different ways in which the messages were created. scenario1() and scenario4() gave incorrect outputs however scenario2() and scenario3() return the message in groups however have incorrect group ids.
--------------------------- code -------------------------------------
import com.ibm.mq.*;
import java.io.IOException;

public class MQGroupTest {

public MQGroupTest() {
}
static int PUT_OPEN_OPTIONS = MQC.MQOO_OUTPUT | MQC.MQOO_SET;

static void scenario1(String qManager, String replyTo, String sendQ)
throws MQException, IOException {
MQQueueManager qMgr = new MQQueueManager(qManager);
MQQueue sendQueue = qMgr.accessQueue(sendQ, PUT_OPEN_OPTIONS,
null, null, null);
MQMessage msg = new MQMessage();
msg.format = MQC.MQFMT_STRING;
msg.messageType = MQC.MQMT_REQUEST;
if (replyTo != null && replyTo.length() > 0) {
msg.replyToQueueName = replyTo;
msg.replyToQueueManagerName = qManager;
}
MQPutMessageOptions pmo = new MQPutMessageOptions();
pmo.options = MQC.MQPMO_LOGICAL_ORDER;
msg.messageFlags = MQC.MQMF_MSG_IN_GROUP;
msg.writeString("1");
sendQueue.put(msg, pmo);
MQMessage msg1 = new MQMessage();
msg1.format = MQC.MQFMT_STRING;
msg1.messageType = MQC.MQMT_REQUEST;
if (replyTo != null && replyTo.length() > 0) {
msg1.replyToQueueName = replyTo;
msg1.replyToQueueManagerName = qManager;
}
msg1.messageFlags = MQC.MQMF_LAST_MSG_IN_GROUP;
msg.writeString("2");
sendQueue.put(msg1, pmo);
sendQueue.close();
sendQueue = null;
qMgr.disconnect(); qMgr = null;
}

static void scenario2(String qManager, String replyTo, String sendQ)
throws MQException, IOException {
MQQueueManager qMgr = new MQQueueManager(qManager);
MQQueue sendQueue = qMgr.accessQueue(sendQ, PUT_OPEN_OPTIONS,
null, null, null);
MQMessage msg = new MQMessage();
msg.format = MQC.MQFMT_STRING;
msg.messageType = MQC.MQMT_REQUEST;
if (replyTo != null && replyTo.length() > 0) {
msg.replyToQueueName = replyTo;
msg.replyToQueueManagerName = qManager;
}
MQPutMessageOptions pmo = new MQPutMessageOptions();
pmo.options = MQC.MQPMO_LOGICAL_ORDER;
msg.messageFlags = MQC.MQMF_MSG_IN_GROUP;
msg.writeString("1");
sendQueue.put(msg, pmo);
MQMessage msgNext = new MQMessage();
msgNext.format = MQC.MQFMT_STRING;
msgNext.messageType = MQC.MQMT_REQUEST;
if (replyTo != null && replyTo.length() > 0) {
msgNext.replyToQueueName = replyTo;
msgNext.replyToQueueManagerName = qManager;
}
msgNext.messageFlags = MQC.MQMF_LAST_MSG_IN_GROUP;
msgNext.writeString("2");
sendQueue.put(msgNext, pmo);
sendQueue.close();
sendQueue = null;
qMgr.disconnect(); qMgr = null;
}

static void scenario3(String qManager, String replyTo, String sendQ)
throws MQException, IOException {
MQQueueManager qMgr = new MQQueueManager(qManager);
MQQueue sendQueue = qMgr.accessQueue(sendQ, PUT_OPEN_OPTIONS,
null, null, null);
MQMessage msg = new MQMessage();
msg.format = MQC.MQFMT_STRING;
msg.messageType = MQC.MQMT_REQUEST;
if (replyTo != null && replyTo.length() > 0) {
msg.replyToQueueName = replyTo;
msg.replyToQueueManagerName = qManager;
}
MQPutMessageOptions pmo = new MQPutMessageOptions();
pmo.options = MQC.MQPMO_LOGICAL_ORDER;
msg.messageFlags = MQC.MQMF_MSG_IN_GROUP;
msg.writeString("1");
sendQueue.put(msg, pmo);
msg.clearMessage(); //clears the buffer, leaves the object attributes intact
msg.messageFlags = MQC.MQMF_LAST_MSG_IN_GROUP;
msg.writeString("2");
sendQueue.put(msg, pmo);
sendQueue.close();
sendQueue = null;
qMgr.disconnect(); qMgr = null;
}

static void scenario4(String qManager, String replyTo, String sendQ)
throws MQException, IOException {
MQQueueManager qMgr = new MQQueueManager(qManager);
MQQueue sendQueue = qMgr.accessQueue(sendQ, PUT_OPEN_OPTIONS,
null, null, null);
MQMessage msg = new MQMessage();
msg.format = MQC.MQFMT_STRING;
msg.messageType = MQC.MQMT_REQUEST;
if (replyTo != null && replyTo.length() > 0) {
msg.replyToQueueName = replyTo;
msg.replyToQueueManagerName = qManager;
}
MQPutMessageOptions pmo = new MQPutMessageOptions();
pmo.options = MQC.MQPMO_LOGICAL_ORDER;
msg.messageFlags = MQC.MQMF_MSG_IN_GROUP;
msg.writeString("1");
msg.clearMessage(); //this will clear the message buffer,
//the variables of this object will not be changed
msg.messageFlags = MQC.MQMF_LAST_MSG_IN_GROUP;
msg.writeString("2");
sendQueue.put(msg, pmo);
sendQueue.close();
sendQueue = null;
qMgr.disconnect(); qMgr = null;
}

public static void main(String[] args) {
try {
scenario1("Q_MGR", "REPLYQ", "PUTQ");
} catch (MQException mqe) {
System.out.println("scenario1 : MQException :" + mqe);
} catch (IOException ioe) {
System.out.println("scenario1 : IOException :" + ioe);
}
try {
scenario2("Q_MGR", "REPLYQ", "PUTQ");
} catch (MQException mqe) {
System.out.println("scenario1 : MQException :" + mqe);
} catch (IOException ioe) {
System.out.println("scenario1 : IOException :" + ioe);
}
try {
scenario3("Q_MGR", "REPLYQ", "PUTQ");
} catch (MQException mqe) {
System.out.println("scenario1 : MQException :" + mqe);
} catch (IOException ioe) {
System.out.println("scenario1 : IOException :" + ioe);
}
try {
scenario4("Q_MGR", "REPLYQ", "PUTQ");
} catch (MQException mqe) {
System.out.println("scenario1 : MQException :" + mqe);
} catch (IOException ioe) {
System.out.println("scenario1 : IOException :" + ioe);
}
}

static {
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
MQEnvironment.hostname = hostname;
MQEnvironment.port = port;
MQEnvironment.channel = channel;
}
}
------------------------ code ends here -------------------------
--------------- output for different scenarios --------------------
scenario 1:
Correlation Id:[B@772617
Encoding:273
Format:MQSTR
Group Id:[B@65e2c3
Message Id:[B@a992f
Message Sequence Number:2
Offset:0
Original Length:-1
Application Type:28

scenario 2:
Correlation Id:[B@772617
Encoding:273
Format:MQSTR
Group Id:[B@65e2c3
Message Id:[B@a992f
Message Sequence Number:1
Offset:0
Original Length:-1
Application Type:28
message:1
length:1
Correlation Id:[B@5c8569
Encoding:273
Format:MQSTR
Group Id:[B@3ab50a
Message Id:[B@43c749
Message Sequence Number:2
Offset:0
Original Length:-1
Application Type:28
message:2
length:1

scenario 3:
Correlation Id:[B@772617
Encoding:273
Format:MQSTR
Group Id:[B@65e2c3
Message Id:[B@a992f
Message Sequence Number:1
Offset:0
Original Length:-1
Application Type:28
message:1
length:1
Correlation Id:[B@5c8569
Encoding:273
Format:MQSTR
Group Id:[B@3ab50a
Message Id:[B@43c749
Message Sequence Number:2
Offset:0
Original Length:-1
Application Type:28
message:2
length:1

scenario 4:
Correlation Id:[B@772617
Encoding:273
Format:MQSTR
Group Id:[B@65e2c3
Message Id:[B@a992f
Message Sequence Number:1
Offset:0
Original Length:-1
Application Type:28
message:2
length:1
------------- end of output ----------------------------------
Back to top
View user's profile Send private message
bower5932
PostPosted: Thu Dec 12, 2002 6:10 am    Post subject: Reply with quote

Jedi Knight

Joined: 27 Aug 2001
Posts: 3023
Location: Dallas, TX, USA

The problems that I see with the above code:

Scenario 1:
Second message in group is not filled in (you use msg.writeString("2") and then put msg1). However, this should work as far as the grouping is concerned. Your output shows only a sequence number of 2 which leads me to believe that you've already gotten sequence number 1.

Scenario 2:
Looks good to me.

Scenario 3:
Looks good to me.

Scenario 4:
Looks like the put for the 1st message is missing.

In addition, your printout at the bottom looks like it is giving the location of the groupId rather than the groupId. Try something like:
Code:

   System.out.println("Group ID: " + msg.groupId);
   System.out.print("Group ID: ");
   for (int i=0; i< 24; i++) {
      System.out.print(Integer.toHexString(msg.groupId[i]));
   }
   System.out.println();

The first line will be something like: [B@65e2c3. The second line will look more like the hex string of the group id (414d51207075627375622e716d67722050ffffff9ffffffff83d522000).

For what it is worth, the toHexString doesn't seem to work correctly when the byte has the high order bit set (ie, ffffff9 comes out). It also doesn't print out the leading 0 on bytes like 0A. However, this should get you past the main problems.

(Does somebody out there no more java than me and how to fix the toHexString?)
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
desinus
PostPosted: Thu Dec 12, 2002 12:59 pm    Post subject: Reply with quote

Newbie

Joined: 10 Dec 2002
Posts: 6
Location: US

I got this issue resolved. Thanks a lot Ron for the examples you sent me. It helped me a lot. I was looking to use message id to correlation id mapping on the grouped messages and could do that. I also tried out segmentation and that worked flawlessly too.
Like you mentioned I was printing the address for the ids instead of the actual byte value.

Thanks once again.
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 » [Solved] message group problem using base java api on NT
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.