|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
need a return code after the message is successfully put |
« View previous topic :: View next topic » |
Author |
Message
|
Vishy |
Posted: Fri Sep 26, 2003 6:35 am Post subject: need a return code after the message is successfully put |
|
|
Novice
Joined: 30 Jul 2003 Posts: 21
|
Hi,
I am retrieving an XML message from the table and could successfully put the message on the Q. My probem is I need a return code which returns 0 or 1 if it was successful in putting the Q or not.
This return code is required to update the status of the previously sent message to Y or processed something like that. Is there a way I can get some kind of return code once the message is put on the Q.
here is the code for that. I am reading the hostname, channelname and portno from a table
Please tell me how to modify this method so that I can get a returncode once the message is put.
Thanks in advance
Vishy
public static String sendMessage(String m_msg,String hn, String ch,int pt) throws MQException, IOException{
MQQueueManager qMgr = null;
String qManager = "TESTQM";
byte[] message_Id = null;
String msgData = null;
MQQueue system_default_local_queue = null;
try{
try{
MQEnvironment.channel = ch;
MQEnvironment.hostname = hn;
MQEnvironment.port = pt;
System.out.println(" MQEnvironment.HOSTNAME IS " + hn);
System.out.println(" MQEnvironment.CHANNELNAME IS " + ch);
System.out.println(" MQEnvironment.PORTNO IS " + pt);
}catch(Exception ex){
System.out.println("Exception in "+ ex.getMessage());
}
System.out.println("message defined 209" + qManager);
// Create a connection to QManager
//qMgr = new MQQueueManager(MQQueueManager(configParams.getProperty("QMGR")));
qMgr = new MQQueueManager(qManager);
System.out.println("message defined 215");
// Set up the options on the Q we wish to open
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
// Now specify the Q that we wish to open and the open options
system_default_local_queue = qMgr.accessQueue("SYSTEM.DEFAULT.LOCAL.QUEUE", openOptions);
// Define a simple message
MQMessage mqMsg = new MQMessage();
System.out.println("message defined 223");
//mqMsg.messageType = MQC.MQMT_REQUEST;
mqMsg.format = MQC.MQFMT_STRING;
mqMsg.priority = MQC.MQPRI_PRIORITY_AS_Q_DEF;
mqMsg.expiry = 1200;
mqMsg.writeString(m_msg);
System.out.println("The message string is" + m_msg);
//mqMsg.replyToQueueName = "SYSTEM.DEFAULT.LOCAL.QUEUE";
// Specify the message options
MQPutMessageOptions mqPMO = new MQPutMessageOptions();
// Put the message on the Q
system_default_local_queue.put(mqMsg,mqPMO);
System.out.println( "The request message was put successfully on the queue");
message_Id = mqMsg.messageId;
System.out.println("The message Id is " + mqMsg.messageId);
}catch(MQException e){
System.out.println("MQException: in QManager,PMO " + e.reasonCode + " " + e.getMessage());
}
try{
// Close the Q
system_default_local_queue.close();
// Disconnect from QueueManager
qMgr.disconnect();
}catch (MQException ex) {
System.out.println("A WebSphere MQ error occurred : Completion code " + ex.completionCode + " Reason code " + ex.reasonCode);
System.exit(1);
} finally {
return msgData;
}
}
[/quote] |
|
Back to top |
|
 |
leonwj |
Posted: Fri Sep 26, 2003 7:02 am Post subject: |
|
|
Newbie
Joined: 16 Sep 2003 Posts: 4 Location: Boston, MA
|
Vishy,
Why do you need a return code? The put is either successful or you're into MQException territory i.e. your catch block. Once in there you can check the severity of the exception and take any appropriate action. i.e. putStatus(failed); etc.
Conversely, after a successful put you could call putStatus(ok); should you wish to perform followup processing.
Regards |
|
Back to top |
|
 |
vennela |
Posted: Fri Sep 26, 2003 7:25 am Post subject: |
|
|
 Jedi Knight
Joined: 11 Aug 2002 Posts: 4055 Location: Hyderabad, India
|
Vishy:
I think it is more of a programming issue. Along with the parameters you pass to the method (like hostname, channel port), pass along another I/O argument (like String PutOK). Inside your method, you update the value of PutOK to either YES or NO depending on whether MQPUT was successful or not.
-------
Venny |
|
Back to top |
|
 |
Vishy |
Posted: Fri Sep 26, 2003 9:05 am Post subject: Thanks |
|
|
Novice
Joined: 30 Jul 2003 Posts: 21
|
|
Back to top |
|
 |
jefflowrey |
Posted: Sat Sep 27, 2003 4:50 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Vishy -
You already are returning a String, you just aren't populating it.
As Vennela said, just set msgData to 'Y' or 'Yes' or something to indicate success, and set it to 'N' or whatever when you catch an exception.
Or inside your exception handlers (catch blocks), just throw a new exception, and catch that in your calling routine. That will tell you if the message was put successfully as well. _________________ I am *not* the model of the modern major general. |
|
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
|
|
|
|