|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
How to get messages into Java application from queues |
« View previous topic :: View next topic » |
Author |
Message
|
reddy_kal |
Posted: Tue Nov 05, 2002 8:45 am Post subject: How to get messages into Java application from queues |
|
|
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 |
|
 |
bower5932 |
Posted: Tue Nov 05, 2002 9:03 am Post subject: |
|
|
 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 |
|
 |
reddy_kal |
Posted: Tue Nov 05, 2002 9:24 am Post subject: How to get messages into Java application from queues |
|
|
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 |
|
 |
abmanesh |
Posted: Tue Nov 05, 2002 10:10 am Post subject: |
|
|
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 |
|
 |
reddy_kal |
Posted: Tue Nov 05, 2002 3:40 pm Post subject: |
|
|
Acolyte
Joined: 04 Nov 2002 Posts: 73
|
Thanks for sending the code |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|