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 API Support » need guidance on API

Post new topic  Reply to topic
 need guidance on API « View previous topic :: View next topic » 
Author Message
mk.gupta
PostPosted: Wed Aug 02, 2006 10:23 pm    Post subject: need guidance on API Reply with quote

Novice

Joined: 27 Mar 2006
Posts: 13
Location: CA, US

Dear all,
I m new to MQ series.
I have one requirement where the custom program(in java), reads the MQ queue synchronously & insert the corresponding message into a Oracle DB. On successful insertion only, it should delete the message from MQ Queue.
I want to know about which MQ based java API classes to be used for synchronous read & how to delete the message after DB updation task.

Please guide me how to acheive this.
_________________
Regrads,
Manish
manishgupta.tcs@gmail.com
Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Aug 02, 2006 11:42 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Everything you need to know is here:

http://publib.boulder.ibm.com/infocenter/wmqv6/v6r0/index.jsp

For your specific needs you should refer to the Application Programming Guide and the Using Java manual, which lay out all the concepts and information you need along with some samples.

MQ supports the concept of unit of work, so there's no problem with syncronising a DB insert with a queue read. You'll find the exact parameters required to request MQ does this in the manual. Likewise, a successfully commited read will automatically remove the message from the queue.

Happy reading!
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mk.gupta
PostPosted: Thu Aug 03, 2006 2:32 am    Post subject: Reply with quote

Novice

Joined: 27 Mar 2006
Posts: 13
Location: CA, US

Thanks Vitor,

I started reading, Also any existing code for reference shall be very helpful.


Thanks,
Manish
_________________
Regrads,
Manish
manishgupta.tcs@gmail.com
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Aug 03, 2006 2:38 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Like I said, there's example code in the manuals. You'll find sample code for most things in with your queue manager installation; the exact location will be in the Quick Beginnings manual for your platform. On Windows it's Program Files\MQ\tools\samp, on Unix it's /var/mqm/opt/samp

Or something like those. It's in the manual anyway.

Be aware that the samples are just that; samples to illustrate a point. They're not necessarially production quality.

Have fun
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu Aug 03, 2006 3:01 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

Also, if you need to guarantee that both the insert and the get are processed atomically, you need XA coordination (two-phase commit).

This requires some slightly different code on your part, and requires some configuration of the queue manager, and requires that your code runs with a server/bindings connection, and not as a client. This means it must run on the same machine as the queue manager.

But, as Vitor says - there's plenty of documentation and pre-supplied samples.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
kevin_22
PostPosted: Thu Aug 03, 2006 3:43 am    Post subject: Reply with quote

Centurion

Joined: 08 Mar 2005
Posts: 100

Find this link for sample code........

http://www-304.ibm.com/jct09002c/isv/tech/sampmq.html
Back to top
View user's profile Send private message
mk.gupta
PostPosted: Thu Aug 03, 2006 3:54 am    Post subject: Reply with quote

Novice

Joined: 27 Mar 2006
Posts: 13
Location: CA, US

Thanks guys,
I got the initial success as i could establish the connection with MQ server & started reading the Message with help of guides....but i couldn't get any reference (hard luck) for clearing the queue after browse.. see my code below, its reading wonderfully from queue but reading same message again & again. say I am successful in updading the DB, how can I clear the queue to read the next message, suppose in next run of program? Please gimme some clue.
Thanks,
Manish


import com.ibm.mq.*;

public class MQBrowse {


/**
* MQBrowse constructor comment.
*/
public MQBrowse() {

MQEnvironment.hostname = "localhost";
MQEnvironment.port = 1415;
MQEnvironment.channel = "SYSTEM.DEF.SVRCONN";
MQEnvironment.userID = "db2admin";
MQEnvironment.password = "P@ssw0rd123";

final String qManager ="BRKQM";
final MQQueueManager qMgr;

try{

// Create a connection to the queue manager

qMgr= new MQQueueManager(qManager);

// Set up the options on the queue we wish to open...
// Note. All MQSeries Options are prefixed with MQC in Java.


// Note: Open the queue for browsing option. (Important)


int openOptions = MQC.MQOO_BROWSE | MQC.MQGMO_LOGICAL_ORDER;

MQQueue system_default_local_queue1 = qMgr.accessQueue("Y.WXX.ORD.INPUT",
openOptions);


MQMessage retrievedMessage =new MQMessage();


// Set the get message options..

MQGetMessageOptions gmo =new MQGetMessageOptions(); // accept the defaults
// same as MQGMO_DEFAULT


gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST;

// get the message off the queue..

system_default_local_queue1.get(retrievedMessage,gmo);
System.out.println("Message retrieved from the queue");

// And prove we have the message by displaying the UTF message text

String msgText =retrievedMessage.readUTF();

System.out.println("The message is:"+msgText);



// Close the queue.
system_default_local_queue1.close();

// Disconnect from the queue manager.
qMgr.disconnect();

} // End of try

// If an error has occurred in the above, try to identify what went wrong.
// Was it an MQSeries error?

catch (MQException ex) {

System.out.println("An MQSeries 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);
}


catch (Exception ex) {

System.out.println("An error occurred whilst writing to the message buffer:"+ex);
} //End of catch.

}
/**
* Insert the method's description here.
* Creation date: (31/07/2006 9:59:30 AM)
* @param args java.lang.String[]
*/
public static void main(String[] args) {
new MQBrowse();
}
}
_________________
Regrads,
Manish
manishgupta.tcs@gmail.com
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Aug 03, 2006 3:58 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

Of course it is - you've specified MQC.MQGMO_BROWSE_FIRST as an option so it's browsing the first message over and over. But why browse? A successful get removes the message from the queue in exactly the way you want.

Spend a bit more time reading, perhaps the Introduction to Messaging and Queuing, before jumping into the code. This really is very, very basic stuff.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Aug 03, 2006 2:58 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20696
Location: LI,NY

And do a search on the manual on syncpoint... but if you need a multiphase commit with a DB you should really be doing it with WAS or Weblogic in JMS and use an external (WAS) J2EE transaction coordinator...


_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
mk.gupta
PostPosted: Fri Aug 04, 2006 2:23 am    Post subject: Reply with quote

Novice

Joined: 27 Mar 2006
Posts: 13
Location: CA, US

Thanks dear,
it worked for me


Regards,
Manish
_________________
Regrads,
Manish
manishgupta.tcs@gmail.com
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 API Support » need guidance on API
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.