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 Java / JMS » Urgent..Sending and Receiving Msg in Group

Post new topic  Reply to topic
 Urgent..Sending and Receiving Msg in Group « View previous topic :: View next topic » 
Author Message
jitendramistry
PostPosted: Tue Feb 12, 2002 4:38 am    Post subject: Reply with quote

Novice

Joined: 04 Feb 2002
Posts: 10
Location: CSSL

Hi,
I am looking for some sample program which send the msg with some group id and retrive it with groupid
Can any body help me in it.?
I have tried to search in this forum but i could not get the complete one for both get and put.

you can also mail me at jitendramistry@hotmail.com

Thanks in advance
Jitendra Mistry
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
bduncan
PostPosted: Tue Feb 12, 2002 10:48 am    Post subject: Reply with quote

Padawan

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

Jitendra,
If you go into the code repository on this site, you should find two programs under the C/C++ section, getgroup.c and putgroup.c. These demonstrate how to put and get a group of messages from a queue, albeit in C. However the MQI calls will be identical for any other language (except JMS of course). But it gives you a general idea of how to do it. If you have any specific questions about message grouping, feel free to post them here.


_________________
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
abmanesh
PostPosted: Tue Feb 12, 2002 11:11 am    Post subject: Reply with quote

Apprentice

Joined: 06 Nov 2001
Posts: 39

Find two sample programs that illustrate message grouping. Could you throw some light on why you want to operate based on group id. 'Am not sure if that is a good idea.



---------- GroupSender.java

import com.ibm.mq.*;

public class GroupSender {

private MQQueueManager qmgr;
private MQQueue outQueue;
private String queueName = "QUEUE1" ;
private String host = "MQLAB" ;
private String channel = "MQLAB.CLIENT" ;
private String qmgrName = "MQLAB.QMGR1" ;
private MQMessage outMsg;
private MQPutMessageOptions pmo;




public static void main (String args[]) {

GroupSender gs = new GroupSender();
gs.runGoupSender();

}
public void runGoupSender() {
try {
init();
sendGroupMessages();
qmgr.commit();
System.out.println("n Messages successfully Send " ) ;
}
catch (MQException mqe) {
mqe.printStackTrace();
try{
System.out.println("n Backing out Transaction " ) ;
qmgr.backout();
System.exit(2);
}
catch(Exception e) {
e.printStackTrace();
System.exit(2);
}
}
catch(Exception e) {
e.printStackTrace();
System.exit(2);
}

}


private void init() throws Exception {

System.out.println("******** 100 ************");
MQEnvironment.hostname = host ;
MQEnvironment.channel = channel ;
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);

qmgr = new MQQueueManager ( qmgrName);
int opnOptn = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING ;
outQueue = qmgr.accessQueue ( queueName , opnOptn,null,null,null ) ;

}

private void sendGroupMessages() throws Exception {

pmo = new MQPutMessageOptions();
// pmo.options = pmo.options + MQC.MQPMO_LOGICAL_ORDER ;
// pmo.options = pmo.options + MQC.MQPMRF_GROUP_ID ;


outMsg = new MQMessage();
outMsg.messageFlags = MQC.MQMF_MSG_IN_GROUP ;
outMsg.format = MQC.MQFMT_STRING ;
String groupId = "111111111111111111111111" ;

outMsg.groupId = groupId.getBytes() ;

String msgData = null;


int i = 10;
while(i > 0) {
msgData = "This is the " + i + " th message in the group " ;
outMsg.writeString(msgData);
if (i == 1)
outMsg.messageFlags = MQC.MQMF_LAST_MSG_IN_GROUP ;

i--;
outQueue.put(outMsg, pmo);
outMsg.clearMessage();

}

}

}



------------------- GroupReceiver.java


import com.ibm.mq.*;

public class GroupReceiver {

private MQQueueManager qmgr;
private MQQueue inQueue;
private String queueName = "QUEUE1" ;
private String host = "MQLAB" ;
private String channel = "MQLAB.CLIENT" ;
private String qmgrName = "MQLAB.QMGR1" ;
private MQMessage inMsg;
private MQGetMessageOptions gmo;




public static void main (String args[]) {

GroupReceiver gs = new GroupReceiver();
gs.runGoupReceiver();

}
public void runGoupReceiver() {
try {
init();
getGroupMessages();
qmgr.commit();
System.out.println("n Messages successfully Send " ) ;
}
catch (MQException mqe) {
mqe.printStackTrace();
try{
System.out.println("n Backing out Transaction " ) ;
qmgr.backout();
System.exit(2);
}
catch(Exception e) {
e.printStackTrace();
System.exit(2);
}
}
catch(Exception e) {
e.printStackTrace();
System.exit(2);
}

}
private void init() throws Exception {

MQEnvironment.hostname = host ;
MQEnvironment.channel = channel ;
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);

qmgr = new MQQueueManager ( qmgrName);
int opnOptn = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_FAIL_IF_QUIESCING ;
inQueue = qmgr.accessQueue ( queueName , opnOptn,null,null,null ) ;



}

private void getGroupMessages() throws Exception {

gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_FAIL_IF_QUIESCING;
gmo.options = gmo.options + MQC.MQGMO_SYNCPOINT ;
gmo.options = gmo.options + MQC.MQGMO_WAIT ;
gmo.waitInterval = 5000 ;
//gmo.options = gmo.options + MQC.MQGMO_ALL_MSGS_AVAILABLE ;
//gmo.options = gmo.options + MQC.MQGMO_LOGICAL_ORDER ;
gmo.matchOptions = MQC.MQMO_MATCH_GROUP_ID ;

inMsg = new MQMessage();
String msgData = null;

String groupId = "111111111111111111111111" ;

inMsg.groupId = groupId.getBytes() ;


while(true) {
inQueue.get(inMsg, gmo);
int msgLength = inMsg.getMessageLength();

msgData = inMsg.readString(msgLength);
System.out.println(" The message is n " + msgData);
char x = gmo.groupStatus ;
System.out.println("n ** The Group Status is : " + x );
if(x == MQC.MQGS_LAST_MSG_IN_GROUP) {
System.out.println("B Last Msg in Group") ;
break;
}
inMsg.clearMessage();



}

}

}



[ This Message was edited by: abmanesh on 2002-02-12 11:12 ]
Back to top
View user's profile Send private message Send e-mail
jitendramistry
PostPosted: Wed Feb 13, 2002 5:54 am    Post subject: Reply with quote

Novice

Joined: 04 Feb 2002
Posts: 10
Location: CSSL

Well My exact requirement is like this.
Let say there are messages in a single queue which are destined for different applications.
Let say when application A1 browses that queue,It should retrive only messages which are destined for A1, all other messages should remain as it is.
similarly when application A2 browses that queue,It should retrive only messages which are destined for A2 only.

Can you suggest me suitable approach, though I understood from books like MsgId,CorrellId,GroupId etc.
But still I am looking for complete PUT/GET sample which is similar to my requirement.

Thanks for any help.

Regards
Jitendra
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
abmanesh
PostPosted: Wed Feb 13, 2002 9:52 am    Post subject: Reply with quote

Apprentice

Joined: 06 Nov 2001
Posts: 39

Hi Jitendra,
The first thought is why not have idividual queues that server each application. If that is not an option you could use the group id to associate a message type and application. Even though logically it is in line, that is not the exact use of grouping in MQ parlance. Any way, in the coded posted earlier, just take out the setting of end of group idicator on the sender (outMsg.messageFlags = MQC.MQMF_LAST_MSG_IN_GROUP ) and remove processing based on the same from the receiver and you should have a working code. Since multiple applications would be accessing the queue set the open option in the receiving applications to MQC.MQOO_INPUT_SHARED .

Back to top
View user's profile Send private message Send e-mail
bduncan
PostPosted: Wed Feb 13, 2002 4:33 pm    Post subject: Reply with quote

Padawan

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

If you are simply trying to differentiate between messages destined for application A and B, then you need to do matching when application A and B do their MQGETs. There are only three attributes you can match against: msgId, correlId, or groupId. While any of these can be made to solve your issue, I would recommend using correlId. If your applications are already using correlIds (for request/reply constructs) then you need to append a watermark to your correlIds. If you are not currently using the correlId attribute, then you simply need to set it to some distinguishing value. In other words, if you are using CorrelIds already, some of your messages on the queue might look like:
CorrelId: 365263423544824236APPA
CorrelId: 542356472342342311APPB
CorrelId: 235235423426567321APPA
Where 'APPA' and 'APPB' are watermarks distinguishing between messages destined for application A versus B.
On the other hand, if you aren't using CorrelIds, you can simply set them to:
CorrelId: APPA
CorrelId: APPB
CorrelId: APPA
etc... where each application does an MQGET matching correlID against either 'APPA' or 'APPB'.
There is no need to use the groupId attribute unless you are actually dealing with mulitiple messages that are logically related. And there's no need to massage the msgId attribute since any watermark scheme you come up with might cause msgIds to no longer be unique, plus, you can't depend on the queue manager to automatically generate them for you anymore...


_________________
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
jitendramistry
PostPosted: Thu Feb 14, 2002 4:13 am    Post subject: Reply with quote

Novice

Joined: 04 Feb 2002
Posts: 10
Location: CSSL

Hi,
Yes I am able to do that.
I have done it through CorrelId and open option MQC.MQOO_INPUT_SHARED.
Thanks both of you for your timely help.

Meanwhile can you tell me, Is it possible to CREATE Q Managers and Queues,using Java code.

Thanks again for your help

Regards
Jitendra Mistry
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
bduncan
PostPosted: Tue Feb 19, 2002 11:40 am    Post subject: Reply with quote

Padawan

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

Jitendra,
You should be able to create queues in your java code using the java PCF API. It allows you to send the same sort of calls you issue within runmqsc. However, as you can imagine, you can't use this interface to create a queue manager, as using PCF requires connecting to a queue manager in the first place. So you can create queues, however, to create queue managers, you'll need some way to invoke the "crtmqm" command on the system from within your java code...


_________________
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
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Urgent..Sending and Receiving Msg in Group
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.