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 » Where is the COMIT??

Post new topic  Reply to topic
 Where is the COMIT?? « View previous topic :: View next topic » 
Author Message
pforand
PostPosted: Wed Apr 16, 2008 5:48 am    Post subject: Where is the COMIT?? Reply with quote

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
View user's profile Send private message
bower5932
PostPosted: Wed Apr 16, 2008 6:06 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
pforand
PostPosted: Wed Apr 16, 2008 6:20 am    Post subject: Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Wed Apr 16, 2008 6:22 am    Post subject: Reply with quote

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
View user's profile Send private message
pforand
PostPosted: Wed Apr 16, 2008 7:16 am    Post subject: Reply with quote

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
View user's profile Send private message
jefflowrey
PostPosted: Wed Apr 16, 2008 7:26 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

A "unit of work" is a "transaction". It's what you "commit" or "rollback".

The method you are looking for is on MQQueueManager.

http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/index.jsp?topic=/com.ibm.mq.csqzaw.doc/uj14870_.htm
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
pforand
PostPosted: Wed Apr 16, 2008 7:39 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » Where is the COMIT??
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.