Author |
Message
|
fjb_saper |
Posted: Tue Jul 19, 2005 1:17 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Quote: |
Mainframe team also says that after "PUT" they tried o write the messages in the flat file the messages are getting written. |
This is no guarantee that the message will ever be viable in MQ. It could be rolled back in MQ and still be in the file.
Quote: |
As the problem is with the VERY FIRST message and not with all the messages we are very much confused.
We tried SYNC_POINT+ Commit but it did not work.
I used qmanager.commit in java. |
When using sync_point do not let the commit happen by any kind of default behavior.
Always explicitely Commit your UOWs and issue an explicit rollback before disconnecting to roll back any unfinished UOW.
Enjoy  |
|
Back to top |
|
 |
gayathri |
Posted: Wed Jul 20, 2005 11:26 pm Post subject: |
|
|
Apprentice
Joined: 07 Jun 2005 Posts: 36
|
Hi,
Please find the sample code I have written in Java to "PUT" messages in MQ which have the problem I have been specifying in the thread.
import com.ibm.mq.*;
import java.io.*;
class MyQueueSend
{
/*Define the name of the host to connect to*/
private String hostname="hostname";
private String channel="TEST.CHANNEL";
private String qManager="QM1";
private MQQueueManager mqManager = null;
private MQQueue mQueue = null;
int depth=0;
private final int ENCODING = 273;
private final int CHARACTER_SET = 437;
/*Initialization*/
public void initialize()
{
MQEnvironment mqe=new MQEnvironment();
MQEnvironment.hostname=hostname;
MQEnvironment.channel=channel;
MQEnvironment.port=1414;
}
public void openIQueue() throws MQException
{
// Sets the connection to bindings or client mode based on value of hostname
MQEnvironment.properties.put (MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
try
{
mqManager = new MQQueueManager(qManager);
}
catch(MQException mqe)
{
System.out.println("Exception:"+mqe.completionCode+"Reason code" +mqe.reasonCode);
}
int openOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING | MQC.MQOO_INQUIRE ;
try
{
mQueue = mqManager.accessQueue("DEV.QUEUE", openOptions,null,null,null);
depth=mQueue.getCurrentDepth();
System.out.println("********QUEUE CURRENT DEPTH********" + depth);
}
catch(MQException mqe)
{
mqe.printStackTrace();
System.out.println("Exception:"+mqe.completionCode+"Reason code" +mqe.reasonCode);
}
}
public void closeQueue() throws MQException{
if (mQueue != null){
mQueue.close();
}
if (mqManager != null){
mqManager.disconnect();
}
}
public void sendMessage(String message) throws MQException,IOException
{
MQMessage mqMessage = new MQMessage();
mqMessage.correlationId = MQC.MQCI_NONE;
mqMessage.messageId = MQC.MQMI_NONE;
mqMessage.encoding = ENCODING;
mqMessage.format = MQC.MQFMT_STRING;
MQPutMessageOptions pmo = new MQPutMessageOptions();
pmo.options = pmo.options | MQC.MQPMO_SYNCPOINT;
mqMessage.writeString(message);
//mqMessage.writeBytes(message);
System.out.println("*****BEFORE PUT*****:" + mQueue.getCurrentDepth());
mQueue.put(mqMessage,pmo);
System.out.println("*****AFTER PUT*****:" + mQueue.getCurrentDepth());
mqManager.commit();
intln("After closing the input queue");
}
public static void main(String args[])
{
MyQueueSend mq=new MyQueueSend();
try
{
mq.initialize();
mq.openIQueue();
for(int i=0 ; i < 5 ;i++)
{
mq.sendMessage("This is message:" +i);
}
System.out.println("******* CURRETNT DEPTH : " + mq.mQueue.getCurrentDepth());
mq.closeQueue();
System.out.println("Queue manager disconnected");
}
catch(MQException me)
{
me.printStackTrace();
}
catch(Exception e)
{
System.out.println("Exception in the queue");
}
}//End of main
}//End of class
Kindly let me know if I have faultered somewhere.
Thanks,
Gayathri |
|
Back to top |
|
 |
bower5932 |
Posted: Thu Jul 21, 2005 5:27 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
I just tried the code above. It wrote five messages onto my queue and it indicated that the current depth was five. After it ended, I used runmqsc to verify that the curdepth was 5 (and it was). I also ran amqsbcg against it and I got back 5 messages.
I did take the liberty of changing the qmgr and channel name. |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Jul 21, 2005 1:55 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
You might want to give a little bit more attention to the error handling.
It could be clearer.
It does not issue an explicit rollback when called (in case of exception...
It does not always close the resource.
Apart from that as bower5932 said there is nothing specifically wrong with it.
Enjoy |
|
Back to top |
|
 |
gayathri |
Posted: Thu Jul 21, 2005 10:29 pm Post subject: |
|
|
Apprentice
Joined: 07 Jun 2005 Posts: 36
|
Hi,
Thanks for your valuable time.
The same "Sender" program does not write 5 messages in the queue always. I have tested that in both mainframe and Windows based MQ server.
This is my receiver program. The program is quite big and I have given the MQ part of the program in this discussion. Please let me know whether there is anything wrong in the reader program.
import com.ibm.mq.*;
public class Receiver {
private String hostname="hostname";
private String channel="TEST.CHANNEL";
private String qManager="QM1";
private MQQueueManager mqManager = null;
private MQQueue queue = null;
private MQGetMessageOptions messageOptions = null;
private MQMessage retrievedMessage = null;
private Object message=null;
/*Initialization*/
public void initialize()
{
MQEnvironment mqe=new MQEnvironment();
MQEnvironment.hostname=hostname;
MQEnvironment.channel=channel;
MQEnvironment.port=1414;
}
public boolean openOQueue() {
// Sets the connection to bindings or client mode based on value of hostname
MQEnvironment.properties.put (MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES);
try
{
mqManager = new MQQueueManager(qManager);
}
catch(MQException mqe)
{
System.out.println("Exception:"+mqe.completionCode+"Reason code" +mqe.reasonCode);
}
messageOptions = new MQGetMessageOptions();
messageOptions.options = messageOptions.options | MQC.MQGMO_WAIT;
messageOptions.waitInterval = MQC.MQWI_UNLIMITED;
try {
int iOpenOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE;
queue = mqManager.accessQueue("DEV.QUEUE", iOpenOptions, null, null, null);
if (queue instanceof MQQueue) {
System.out.println("Error in accessing the queue");
}
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
public void closeQueue() {
try {
queue.close();
System.out.println("Queue closed");
} catch (MQException me) {
}
}
private Object readMessage() throws MQException {
try {
retrievedMessage = new MQMessage();
queue.get(retrievedMessage, messageOptions);
int len=retrievedMessage.getTotalMessageLength();
byte[] msgAsBytes= new byte[len];
retrievedMessage.readFully(msgAsBytes);
message=new String(msgAsBytes,"Cp037");
System.out.println("Message read is:" +message);
} catch (Exception e) {
e.printStackTrace();
}
return message;
}
public static void main(String args[])
{
Receiver receiver=new Receiver();
try
{
receiver.initialize();
receiver.openOQueue();
for(int i=0;i <5;i++)
{
receiver.readMessage();
}
receiver.closeQueue();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
This error handling might not be proper. So please don't consider that. Kindly let me know whether the MQ part of the program is correct. As my MQServer is in mainframes I am reading the message as bytes and converting it to String.
Thanks,
Gayathri |
|
Back to top |
|
 |
bower5932 |
Posted: Fri Jul 22, 2005 6:12 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
I just ran the above after running your sender program. I get back all 5 messages that I put. I haven't done extensive testing, but I'd say that the sender program does write 5 messages all of the time (barring a fatal error) and that the receiver will pick all 5 up. |
|
Back to top |
|
 |
gayathri |
Posted: Mon Jul 25, 2005 7:56 pm Post subject: |
|
|
Apprentice
Joined: 07 Jun 2005 Posts: 36
|
Hi,
Thanks a lot. Shall I assume that both the sender and the receiver program is correct?
Please let me know about the fatal error you got.
Thanks,
Gayathri |
|
Back to top |
|
 |
gayathri |
Posted: Wed Jul 27, 2005 9:51 pm Post subject: |
|
|
Apprentice
Joined: 07 Jun 2005 Posts: 36
|
Hi,
The problem is fixed. This is because of closing my Tomcat abruptly.
If the queue is not closed properly and if the GMO option is WAIT_UNLIMITED the control with not go to the closeQueue and the sender will assume that the receiver is there to receive the message. The queue is still open.
If I close the queue properly the message is not lost.
Thanks everyone for your replies and for your valuable time.
Gayathri |
|
Back to top |
|
 |
|