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 » How to get messages into Java application from queues

Post new topic  Reply to topic
 How to get messages into Java application from queues « View previous topic :: View next topic » 
Author Message
reddy_kal
PostPosted: Tue Nov 05, 2002 8:45 am    Post subject: How to get messages into Java application from queues Reply with quote

Acolyte

Joined: 04 Nov 2002
Posts: 73

Hi,
Can anyone help me how can I retrieve messages from queue into Java application.
I have one queue (Test) in the queueManager(QM2). There are some messages in the Test queue. I want to retreive those messages and store that in the form of string.

Can anyone help me in this.

Thanks
Back to top
View user's profile Send private message
bower5932
PostPosted: Tue Nov 05, 2002 9:03 am    Post subject: Reply with quote

Jedi Knight

Joined: 27 Aug 2001
Posts: 3023
Location: Dallas, TX, USA

I'm not sure that I understand your question. There are several programs in the software repository that get messages:

mqjmssel.java.tar.gz
mqjmssrv.java.tar.gz
backout.java.tar.gz

There are also others. You might want to look at one of them and see if they show you what you are trying to do.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger
reddy_kal
PostPosted: Tue Nov 05, 2002 9:24 am    Post subject: How to get messages into Java application from queues Reply with quote

Acolyte

Joined: 04 Nov 2002
Posts: 73

Thanks for the reply.

Actually I have one local queue by name "Test" in one of my Queue Manager by name "QM2".
I put some messages in the Test queue using MQExplorer.
From Java application I want to retrieve these messages and store that into a string.

Thanks in advance
Back to top
View user's profile Send private message
abmanesh
PostPosted: Tue Nov 05, 2002 10:10 am    Post subject: Reply with quote

Apprentice

Joined: 06 Nov 2001
Posts: 39

Here is a skeleton for getting the message. Refer the Using Java Manual for more details.
This should get you started. Rememember the MQ Object names such as Queue Manager Names,
Queue Name etc., are case sensitive.


step 1import com.ibm.mq.* package

Step 2
For connecting to the Queue Manger as a client set the environment options


MQEnvironment.hostname = "HostName ";
MQEnvironment.channel = "Channel Name" ;
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,
MQC.TRANSPORT_MQSERIES);

Step 3

Connect to the queue manager QM2

MQQueueManager qmgr = new MQQueueManager("QM2" ) ;


Step 4
Set Open Options for Opening the Queue to get messages

int openOptions = MQC.MQOO_INPUT_SHARED | MQC.MQOO_FAIL_IF_QUIESCING;

Step 5
Open the Queue named Test using the above open option

MQQueue queue = qMgr.accessQueue(queueName, openOptions, null, null, null);

Step 6
Set Get Message options

MQGetMessageOptions gmo = new MQGetMessageOptions() ;

Step 7
Create a Message Buffer to read the message into

MQMessage inMsg = new MQMessage();

Step 8
Read the message into the message buffer



queue.get(inMsg, gmo);

Step 9
For reading the string message, get the length of the message

int msgLength = inMsg.getMessageLength() ;


Stp 10

Get the message data as string


String msgTxt = inMsg.readString(msgLength);



Then commit the transaction using qmgr.commit( )

close objects and diconnect from the queuemanager with
qmgr.disconnect() ;
Back to top
View user's profile Send private message Send e-mail
reddy_kal
PostPosted: Tue Nov 05, 2002 3:40 pm    Post subject: Reply with quote

Acolyte

Joined: 04 Nov 2002
Posts: 73

Thanks for sending the code
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 » How to get messages into Java application from queues
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.