Author |
Message
|
pforand |
Posted: Wed Apr 16, 2008 5:48 am Post subject: Where is the COMIT?? |
|
|
Newbie
Joined: 16 Apr 2008 Posts: 4
|
Hi
I am currently upgrading a Java program, which does "MQGet" until a Queue is empty. The code is simple, but I can't seem to find the "COMIT" part. Can someone tell me where the COMIT is ? I am fairly new to MQSeries (and java..) so your help will be appreciated.
Thanks !!!
F
edit : forgot the code :
Code: |
import com.ibm.mq.*;
import java.io.IOException;
import java.util.Date;
import java.util.Hashtable;
import java.util.Random;
import java.io.*;
public class MQRead
{
private MQQueueManager _queueManager = null;
private Hashtable params = null;
public int port = 1421;
public String hostname = "XXXXXXX";
public String channel = "XXXXXXXXXX";
public String qManager = "XXXXXXXXXXXX";
public String inputQName = "XXXXXXXXX";
public MQRead()
{
super();
}
private boolean allParamsPresent()
{
boolean b = params.containsKey("-h") &&
params.containsKey("-p") &&
params.containsKey("-c") &&
params.containsKey("-m") &&
params.containsKey("-q");
if (b)
{
try
{
port = Integer.parseInt((String) params.get("-p"));
}
catch (NumberFormatException e)
{
b = false;
}
// Set up MQ environment
hostname = (String) params.get("-h");
channel = (String) params.get("-c");
qManager = (String) params.get("-m");
inputQName = (String) params.get("-q");
}
return b;
}
private void init(String[] args) throws IllegalArgumentException
{
params = new Hashtable(5);
if (args.length > 0 && (args.length % 2) == 0)
{
for (int i = 0; i < args.length; i+=2)
{
params.put(args[i], args[i+1]);
}
}
else
{
throw new IllegalArgumentException();
}
if (allParamsPresent())
{
MQEnvironment.hostname = hostname;
MQEnvironment.channel = channel;
MQEnvironment.port = port;
}
else
{
throw new IllegalArgumentException();
}
}
public static void main(String[] args)
{
MQRead readQ = new MQRead();
try
{
readQ.init(args);
readQ.selectQMgr();
readQ.read();
}
catch (IllegalArgumentException e)
{
System.out.println("Utilisation: java MQRead <-h host> <-p port> <-c channel> <-m QueueManagerName> <-q QueueName>");
System.exit(1);
}
catch (MQException e)
{
System.out.println(e);
System.exit(1);
}
}
private void read() throws MQException
{
int openOptions = MQC.MQOO_FAIL_IF_QUIESCING + MQC.MQOO_INPUT_SHARED;
MQQueue queue = _queueManager.accessQueue( inputQName,
openOptions,
null,
null,
null );
System.out.println("Connexion MQRead OK.\n");
MQGetMessageOptions getOptions = new MQGetMessageOptions();
getOptions.options = MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING + MQC.MQGMO_CONVERT;
while(true)
{
Date now = new Date();
MQMessage message = new MQMessage();
try
{
queue.get(message, getOptions);
byte[] b = new byte[message.getMessageLength()];
message.readFully(b);
try
{
FileWriter fstream = new FileWriter("p:\\OUTPUT_MQRead\\" + now.getTime()+ ".hst");
BufferedWriter out = new BufferedWriter(fstream);
out.write(new String(b));
System.out.println(new String(b));
out.close();
Thread.sleep(500); }
catch (Exception e)
{
System.err.println("Error lors de l'écriture du fichier " + now.getTime() + ".hst : " + e.getMessage());
}
message.clearMessage();
}
catch (IOException e)
{
System.out.println("Erreur GET: " + e.getMessage());
break;
}
catch (MQException e)
{
if (e.completionCode == 2 && e.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE)
{
System.out.println("Queue vidée");
}
break;
}
}
queue.close();
_queueManager.disconnect();
}
private void selectQMgr() throws MQException
{
_queueManager = new MQQueueManager(qManager);
}
}
|
Thanks !!! |
|
Back to top |
|
 |
bower5932 |
Posted: Wed Apr 16, 2008 6:06 am Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
You don't have to do your work inside of a unit of work, and it looks like this program doesn't. If you'll go to:
http://www-304.ibm.com/jct09002c/isv/tech/sampmq.html
and search for mqsync, you'll find some samples. They do it with puts instead of gets, but it should give you what you are looking for. |
|
Back to top |
|
 |
pforand |
Posted: Wed Apr 16, 2008 6:20 am Post subject: |
|
|
Newbie
Joined: 16 Apr 2008 Posts: 4
|
Arg. I don't understand...
I was under the impression that when a GET is called, a COMMIT has to be issued to tell the QMgr that the message is processed.
But in this program, I can't find the commit. I just need to be sure that the commit is issued after the message is written in a file. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Apr 16, 2008 6:22 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
pforand wrote: |
I was under the impression that when a GET is called, a COMMIT has to be issued to tell the QMgr that the message is processed.
|
Wrong impression. It's perfectly legal to do gets (or puts) outside a unit of work. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
pforand |
Posted: Wed Apr 16, 2008 7:16 am Post subject: |
|
|
Newbie
Joined: 16 Apr 2008 Posts: 4
|
Thanks. Can you give me more detail on the unit of work ?
What is it? I have never heard this term. |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Apr 16, 2008 7:26 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
|
Back to top |
|
 |
pforand |
Posted: Wed Apr 16, 2008 7:39 am Post subject: |
|
|
Newbie
Joined: 16 Apr 2008 Posts: 4
|
So, basicly, i need to add MQC.MQGMO_SYNCPOINT to my "GET" and then throw in a commit once my file is written ?
This way, I would ensure that in case of a problem (network failure, etc etc), the message would still be available in the Q if it's not written in my file ?
 |
|
Back to top |
|
 |
|