|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Sample code for MatchByMsgID or CorrelID |
« View previous topic :: View next topic » |
Author |
Message
|
ddm |
Posted: Mon Nov 15, 2004 3:08 pm Post subject: Sample code for MatchByMsgID or CorrelID |
|
|
Apprentice
Joined: 17 Nov 2003 Posts: 40
|
Im getting really frustated...
I can't make my code work if I specify a 24 byte MessageID or 24 byte CorrelationID... Im getting a 2033 error code.
What are the proper PutMessageOption/GetMessageOption that I need to set?
Better yet, can you guys provide me with a sample code that is able to retrieve a Message through custom MessageID or CorrelationID..
Thanks! |
|
Back to top |
|
 |
kirani |
Posted: Mon Nov 15, 2004 3:11 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
What have you tried so far? Please post your code.
Here is the link to sample programs at IBM site.
http://www.developer.ibm.com/en_US/tech/sampmq.html _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
ddm |
Posted: Mon Nov 15, 2004 5:14 pm Post subject: |
|
|
Apprentice
Joined: 17 Nov 2003 Posts: 40
|
I made to work SOMETIMES, however it takes at least 40-50 secs, it een got to 5mins to retrieve a message which is pretty unacceptable. Any ideas/special option that I need to put in in order to make this faster?
My getOptions = GetMessageOption.WAIT|GetMessageOption.CONVERT|GetMessageOption.FAIL_IF_QUIESCING;
My matchOptions =MatchMessageOption.MATCH_BY_MessageID
Here's my code:
private object getMessageImpl(byte[] correlationID, MessageFormat messageFormat, int getOptions, int matchOptions, string xmlFileName)
{
SmiMessage smiMessage;
string getMessageType = string.Empty;
StringBuilder getMessage = new StringBuilder();
try
{
MQMessage mqMessage;
mqMessage = new MQMessage();
if(matchOptions == MatchMessageOption.MATCH_BY_CORRELLATION_ID)
{
mqMessage.CorrelationId = correlationID;
}
else if(matchOptions == MatchMessageOption.MATCH_BY_MESSAGE_ID)
{
mqMessage.MessageId = correlationID;
}
MQGetMessageOptions mqGetMessageOptions = new MQGetMessageOptions();
if (getOptions != -1)
{
mqGetMessageOptions.Options = getOptions;
}
if (matchOptions != -1)
{
mqGetMessageOptions.MatchOptions = matchOptions;
}
if (this.WaitInterval > -1) //check if there is an existing options set by the user.
//if there is, we need to add the 'wait' option
{
if (getOptions != -1)
{
mqGetMessageOptions.Options = getOptions|MQC.MQGMO_WAIT;
}
//otherwise, just set the option to 'wait'
else
{
mqGetMessageOptions.Options = MQC.MQGMO_WAIT;
}
mqGetMessageOptions.WaitInterval = this.WaitInterval;
}
else if (this.WaitInterval == -1)
{
mqGetMessageOptions.WaitInterval = MQC.MQWI_UNLIMITED;
}
this.queue.Get(mqMessage, mqGetMessageOptions);
getMessage = new StringBuilder(mqMessage.ReadString(mqMessage.MessageLength));
//--> rest of code... |
|
Back to top |
|
 |
kirani |
Posted: Mon Nov 15, 2004 11:47 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Are you sure that the message that you are trying to read is available on the queue before you call MQGET? Could it be that your message is coming on the queue after you wait for few seconds/mins.
How many messages do you have on the queue? Do you use any wrapper classes in your code? _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
thravi |
Posted: Tue Nov 23, 2004 2:06 pm Post subject: |
|
|
Novice
Joined: 16 Jul 2004 Posts: 13
|
U can use this as
java DeleteMessage Queue_name Queue_Manage_name MsgId
MsgId - the hex dump from amqsbcg
eg:
MsgId : X'414D5120514D3120202020202020202041A3B27620000202'
give MsgId as 414D5120514D3120202020202020202041A3B27620000202
import com.ibm.mq.*; // Include the WebSphere MQ classes for Java package
import java.math.BigInteger;
public class DeleteMessage
{
//private String qManager = args[1];
private MQQueueManager qMgr;
public static void main(String args[]) {
new DeleteMessage(args[0],args[1],args[2]);
}
public DeleteMessage(String qName,String qmgrName,String messageID) {
try {
String qManager = qmgrName;
qMgr = new MQQueueManager(qManager);
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF |
MQC.MQOO_OUTPUT ;
MQQueue que = qMgr.accessQueue(qName,openOptions);
MQMessage retrievedMessage = new MQMessage();
retrievedMessage.messageId = new BigInteger(messageID, 16).toByteArray();
// Set the get message options...
MQGetMessageOptions gmo = new MQGetMessageOptions(); // accept the defaults
// same as MQGMO_DEFAULT
// get the message off the queue...
que.get(retrievedMessage, gmo);
// And prove we have the message by displaying the message text
dumpHexMessage(retrievedMessage);
// Close the queue...
que.close();
// Disconnect from the queue manager
qMgr.disconnect();
}
catch (MQException ex)
{
System.out.println("A WebSphere MQ error occurred : Completion code " +
ex.completionCode + " Reason code " + ex.reasonCode);
}
// Was it a Java buffer space error?
catch (java.io.IOException ex)
{
System.out.println("An error occurred whilst writing to the message buffer: " + ex);
}
}
/*************************************************************/
/* This method will dump the text of the message in both hex */
/* and character format. */
/*************************************************************/
static void dumpHexMessage(MQMessage myMsg) throws java.io.IOException {
int DataLength = myMsg.getMessageLength();
int ch = 0;
int chars_this_line = 0;
int CHARS_PER_LINE = 16;
StringBuffer line_text = new StringBuffer();
line_text.setLength(0);
do {
chars_this_line = 0;
String myPos = new String(Integer.toHexString(ch));
for (int i=0; i < 8 - myPos.length(); i++) {
//System.out.print("0");
}
//System.out.print((String)(Integer.toHexString(ch)).toUpperCase() + ": ");
while ( (chars_this_line < CHARS_PER_LINE) &&
(ch < DataLength) ) {
if (chars_this_line % 2 == 0) {
//System.out.print(" ");
}
char b = (char)(myMsg.readUnsignedByte() & 0xFF);
if (b < 0x10) {
//System.out.print("0");
}
//System.out.print((String)(Integer.toHexString(b)).toUpperCase());
/***********************************************/
/* If this is a printable character, print it. */
/* Otherwise, print a '.' as a placeholder. */
/***********************************************/
if (Character.isLetterOrDigit(b)
|| Character.getType(b) == Character.CONNECTOR_PUNCTUATION
|| Character.getType(b) == Character.CURRENCY_SYMBOL
|| Character.getType(b) == Character.MATH_SYMBOL
|| Character.getType(b) == Character.MODIFIER_SYMBOL
|| Character.getType(b) == Character.UPPERCASE_LETTER
|| Character.getType(b) == Character.SPACE_SEPARATOR
|| Character.getType(b) == Character.DASH_PUNCTUATION
|| Character.getType(b) == Character.START_PUNCTUATION
|| Character.getType(b) == Character.END_PUNCTUATION
|| Character.getType(b) == Character.OTHER_PUNCTUATION ) {
line_text.append(b);
} else {
line_text.append('.');
}
chars_this_line++;
ch++;
}
/*****************************************************/
/* pad with blanks to format the last line correctly */
/*****************************************************/
if (chars_this_line < CHARS_PER_LINE) {
for ( ;chars_this_line < CHARS_PER_LINE; chars_this_line++) {
if (chars_this_line % 2 == 0) System.out.print(" ");
System.out.print(" ");
line_text.append(' ');
}
}
System.out.println(" '" + line_text.toString() + "'");
line_text.setLength(0);
} while (ch < DataLength);
} /* end of dumpHexMessage */
} // end of DeleteMessage |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|