|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Mapping MQ message to a JMS message |
« View previous topic :: View next topic » |
Author |
Message
|
Prasad Katti |
Posted: Wed Aug 10, 2005 11:47 am Post subject: Mapping MQ message to a JMS message |
|
|
Newbie
Joined: 10 Aug 2005 Posts: 2
|
Hi All,
I am a newbie to MQ. Currently, I am doing something like this.
1. Develop a simple program. that will put MQ messages on a queue on the server using MQI classes. This is a text message.
Code: |
queue = queueManager.accessQueue(QUEUE_NAME, openOptions, null, null, null);
message.writeUTF(text);
//Mesage options.
System.out.println("Setting Put Message Options");
MQPutMessageOptions pmo = new MQPutMessageOptions();
//put the message on the queue.
System.out.println("Putting the message on the queue");
queue.put(message);
//close queue.
System.out.println("Closing the queue");
queue.close();
//disconnect from the queue.
System.out.println("Disconnecting from the queue manager");
queueManager.disconnect();
|
where text is a valid text data.
2. Develop a receiver program using JMS that will try to get messages from the queue specified above.
Code: |
System.out.println("Setting the transport type");
factory.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
System.out.println("Settign the queue mgr");
factory.setQueueManager(QUEUE_MANAGER);
System.out.println("Setting the host name");
factory.setHostName(hostname);
System.out.println("Setting the port");
factory.setPort(PORT);
System.out.println("Setting the channel");
factory.setChannel(channel);
System.out.println("creating the connection");
connection = factory.createQueueConnection();
System.out.println("Creating the session");
session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
System.out.println("Creating the queue");
Queue queue = session.createQueue(QUEUE_NAME);
System.out.println("Creating the Queue Receiver");
QueueReceiver queueReceiver = session.createReceiver(queue);
System.out.println("Receiving the message");
Message inMessage = null;
inMessage = queueReceiver.receive(5000);
if(inMessage == null){
System.out.println("message is null");
System.exit(0);
}
System.out.println("Got the message ");
String replyString = ((TextMessage) inMessage).getText();
System.out.println("Got the message "+replyString);
System.out.println("Closing the connection to JMS server");
connection.close();
|
When I run the above programs, messages pile up on the MQ server. However, the JMS receiver encounters a NullPointer exception as the statement "queueReceiver.receive(5000);" fails to retrieve the message from the queue.
I need to know how to map the MQ message to a JMS message. What parameters do I need to set in the Sending MQ program and what fields should I look for in my JMS receiver?
Also, how can I set these parameters?
regards
Prasad |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Aug 10, 2005 5:57 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
You forgot to start the connection
Code: |
connection.start();
do {
message = receiver.receive(5000);
if (message == null) exit;
// process the message
} while (message !=null);
connection.stop();
|
Check out your manual. You will only receive messages when the connection is started...
Enjoy  |
|
Back to top |
|
 |
Prasad Katti |
Posted: Thu Aug 11, 2005 11:29 am Post subject: |
|
|
Newbie
Joined: 10 Aug 2005 Posts: 2
|
Thanks. this worked.
Prasad |
|
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
|
|
|
|