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 » How to get the message Id & group ID from a MQ message.

Post new topic  Reply to topic
 How to get the message Id & group ID from a MQ message. « View previous topic :: View next topic » 
Author Message
kvimlesh
PostPosted: Tue Nov 04, 2008 10:43 pm    Post subject: How to get the message Id & group ID from a MQ message. Reply with quote

Newbie

Joined: 04 Nov 2008
Posts: 7

Hi,
We have an application which is creating the MD of a MQ message and putting in the queue. There are some other application running in AIX environment which is checking the MD information's and calling to correct API to process the message. I have written a java code which is taking the message from the this queue and passing it to the another queue from which the other application is picking up, but some how when I am calling the MQMessage constructor, it is resetting the value of the Message descriptor and because of this the correct API is not getting called.

Is it possible to read the MD values from the message in the queue and copy it in the message generated by my java code. I don't have the control of the application which is putting the message in the queue, so we can't change the application code.

Please help.

Thanks..
Vimlesh
Back to top
View user's profile Send private message
David.Partridge
PostPosted: Wed Nov 05, 2008 12:32 am    Post subject: Reply with quote

Master

Joined: 28 Jun 2001
Posts: 249

Look at the programming guide and reference manuals and specifically look at the "pass all context" option when used to put a message.
_________________
Cheers,
David C. Partridge
Back to top
View user's profile Send private message
kvimlesh
PostPosted: Wed Nov 05, 2008 8:10 am    Post subject: Reply with quote

Newbie

Joined: 04 Nov 2008
Posts: 7

I don't want to put the message in the queue, rather try to get the entire message (MD + Data) from a queue and later try to use the MQMD variables.
Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Nov 05, 2008 8:35 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

kvimlesh wrote:
I don't want to put the message in the queue, rather try to get the entire message (MD + Data) from a queue and later try to use the MQMD variables.


This isn't what you said in your original post, where you talked about having a java code which took the message from the queue and passed it to another queue. In this instance, you'd need to pass context to prevent the message id being reset, as indicated in this thread.

If you get a message from the queue the values from the MQMD are available to your code. How they are presented depends on if you're using JMS or native code, and I refer you to the Java manual for a detailed description of this.

There's no reason why you couldn't store this information someplace if you need to use it later. But storing it in the message is an odd place to put it, the other reading application will not expect that.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
kvimlesh
PostPosted: Sat Nov 08, 2008 11:14 am    Post subject: Reply with quote

Newbie

Joined: 04 Nov 2008
Posts: 7

Hi,

here is my get function.

private String getMessage(int iTimeToWait)
{
try
{
MQMessage retrievedMessage = new MQMessage();

MQGetMessageOptions gmo = new MQGetMessageOptions();
if (iTimeToWait<0) {
gmo.waitInterval = MQC.MQWI_UNLIMITED;
} else if (iTimeToWait<100) {
// We cannot go below 100ms
gmo.waitInterval = 100;
} else {
gmo.waitInterval =iTimeToWait;
}
gmo.options = MQC.MQGMO_WAIT;

m_QueueIn.get(retrievedMessage, gmo);
int len = retrievedMessage.getMessageLength();
byte [] buf = new byte[len];
retrievedMessage.readFully(buf);
String str1 = new String(buf);
String str2= "c:\\Alis\\Request\\"+getDate();
boolean status = new File(str2).mkdir();
java.io.File file = new java.io.File(str2,"Archive_"+getDateTime()+".txt");
FileWriter out = new FileWriter(file);
out.write(str1);
out.close();


return str1;

}

Later on I am calling the PUT function, with the String which is coming out from the get method.

private void putMessage(String csMsg,int expiryTime)
{

try
{
MQMessage message = new MQMessage();
message.messageFlags = MQC.MQMF_MSG_IN_GROUP;


message.format = MQC.MQFMT_STRING;
if (expiryTime<0) {
message.expiry = MQC.MQEI_UNLIMITED;
} else if (expiryTime<100) {
// We cannot go below 100ms
message.expiry = 1;
} else
message.expiry =expiryTime/100;

message.writeBytes(csMsg);
MQPutMessageOptions pmo = new MQPutMessageOptions();

m_QueueOut.put(message,pmo);
}
catch (MQException e)
{
System.out.println(e.getMessage());
//throw new RuntimeException (e.getMessage(), e);
}
catch (Exception e)
{
System.out.println(e.getMessage());
//throw new RuntimeException (e.getMessage(), e);
}
}

what should i change in the code, so that it put the same MQMD value of the message which is there in the queue.

Thanks
Vimlesh
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sat Nov 08, 2008 7:03 pm    Post subject: Reply with quote

Grand High Poobah

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

Go back to the drawing board and review the complete design.
Why do you need to have the message put to a file?
If that is the case I would not worry about a thing. The message is serializable and as such I would just write it to the file as an object.
Advantage: reading it back in you get the message with all it's original components (MQMD etc...). Don't have to worry whether it is a message containing text or anything else...

So read again all the advice you have been given and go back to the drawing board. From your comments about time to wait in your code, I doubt that you understand correctly the role of the middleware and how the message should always be available as soon as possible.

Enjoy
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » How to get the message Id & group ID from a MQ message.
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.