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 » Mapping MQ message to a JMS message

Post new topic  Reply to topic
 Mapping MQ message to a JMS message « View previous topic :: View next topic » 
Author Message
Prasad Katti
PostPosted: Wed Aug 10, 2005 11:47 am    Post subject: Mapping MQ message to a JMS message Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Wed Aug 10, 2005 5:57 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Prasad Katti
PostPosted: Thu Aug 11, 2005 11:29 am    Post subject: Reply with quote

Newbie

Joined: 10 Aug 2005
Posts: 2

Thanks. this worked.

Prasad
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 » Mapping MQ message to a JMS message
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.