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 Installation/Configuration Support » Problem in sending/recieving messages from my Java program

Post new topic  Reply to topic
 Problem in sending/recieving messages from my Java program « View previous topic :: View next topic » 
Author Message
Praveen
PostPosted: Sat Nov 09, 2002 10:39 pm    Post subject: Problem in sending/recieving messages from my Java program Reply with quote

Apprentice

Joined: 23 Oct 2002
Posts: 40
Location: Bangalore

Hi All,
I had installed MQ server and client on my Win 2k machine and even I had installed the same on my Sun Solaris machine. According to the instructions given in Quick Beginnings I had created the required Queue Managers, Queues, Channels on both the machines. Then I was able to send and receive the messages from Win 2k machine to Sun machine by amqsput and amqsget. But when I am trying to do the same by running my java program I am not able to do that, its giving me open options error, I had tried with the different options of the open options but still the same error. I am sending my program for your reference. Before running this program I am starting Queue Managers of both machines and running the following command which will automatically start even the channel of Receiver

runmqchl -c SENDER.CHANNEL -m MYQM

Here SENDER.CHANNEL is the channel through which I will be sending the message. I had created one local definition of Remote Queue also.
Can anybody please guide me what I am missing here or what other instructions I need to follow if I am trying to send the messages by my java program.



Code:

import com.ibm.mq.*;
import java.io.*;


public class MQSample
{
   private String qManager = "MYQM";

   private MQQueueManager qMgr;

   public static void main(String args[]) {
      new MQSample();
   }

   public MQSample(){
      try{
         qMgr = new MQQueueManager(qManager);
            int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT ;
 //MQC.MQOO_OUTPUT; // | MQC.MQOO_INPUT_EXCLUSIVE; // MQC.MQOO_INQUIRE // | MQC.MQOO_SET | MQC.MQOO_INPUT_SHARED; // | MQC.MQOO_INPUT_EXCLUSIVE | MQC.MQOO_INPUT_AS_Q_DEF; // | MQC.MQOO_OUTPUT | MQOO_INPUT_SHARED | MQOO_INPUT_EXCLUSIVE | MQOO_BROWSE | MQOO_INQUIRE | MQ_SET

         MQQueue system_default_local_queue = qMgr.accessQueue("LOCAL.DEF.OF.REMOTE.QUEUE", openOptions);

         MQMessage hello_world = new MQMessage();
         hello_world.writeUTF("Hello World!");

         MQPutMessageOptions pmo = new MQPutMessageOptions();

         system_default_local_queue.put(hello_world,pmo);

      //   MQQueue recieve_queue = qMgr.accessQueue("SENDER.QUEUE", openOptions);

         MQMessage retrievedMessage = new MQMessage();
         retrievedMessage.messageId = hello_world.messageId;

         MQGetMessageOptions gmo = new MQGetMessageOptions();

         system_default_local_queue.get(retrievedMessage, gmo);

      // recieve_queue.get(retrievedMessage, gmo);

         String msgText = retrievedMessage.readUTF();
         System.out.println("Retrieved Message is...." + msgText);
         system_default_local_queue.close();

         qMgr.disconnect();
      }
         catch (MQException ex)
      {
            System.out.println("An MQSeries error occurred : Completion code " + ex.completionCode + " Reason code " + ex.reasonCode);
      }

      catch (java.io.IOException ex)
      {
         System.out.println("An error occurred whilst writing to the message buffer: " + ex);
      }
   }
}

In the above example I have not included the IP of Reciever machine, is it necessary to mention it?, if so how??. And moreover I had installed the MQ Classes for Java only on sender mahice, is it necassary to install it on reciever machine?

Sorry for posting a long message. Help please
_________________
Thanks,

Praveen K
Back to top
View user's profile Send private message
vennela
PostPosted: Sun Nov 10, 2002 8:04 am    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

Praveen:

Your MQ setup is just fine. You have even tested that with amqsput and amqsget. I think I know what you are missing here.

The program that is shown there has two parts in it.
1. It will put a message to the Queue LOCAL.DEF.OF.REMOTE.QUEUE on the QMGR MYQM.
2. It will get the message from the Queue LOCAL.DEF.OF.REMOTE.QUEUE on the QMGR MYQM.

Now if I guess it right (atleast by the name of the Queue) your Queue is a remote Queue. You can only "PUT" to a remote Queue and you cannot GET.

So you have to remove the second part of the program. Just run the first part and the Hello World message will show up on the other QMGR.

You may just try the complete program on a Local Queue.

I am purging your program so that it contains only the PUTTING part of the code and posting it here below.

import com.ibm.mq.*;
import java.io.*;


public class MQSample
{
private String qManager = "MYQM";

private MQQueueManager qMgr;

public static void main(String args[]) {
new MQSample();
}

public MQSample(){
try{
qMgr = new MQQueueManager(qManager);
int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT ;
//MQC.MQOO_OUTPUT; // | MQC.MQOO_INPUT_EXCLUSIVE; // MQC.MQOO_INQUIRE // | MQC.MQOO_SET | MQC.MQOO_INPUT_SHARED; // | MQC.MQOO_INPUT_EXCLUSIVE | MQC.MQOO_INPUT_AS_Q_DEF; // | MQC.MQOO_OUTPUT | MQOO_INPUT_SHARED | MQOO_INPUT_EXCLUSIVE | MQOO_BROWSE | MQOO_INQUIRE | MQ_SET

MQQueue system_default_local_queue = qMgr.accessQueue("LOCAL.DEF.OF.REMOTE.QUEUE", openOptions);

MQMessage hello_world = new MQMessage();
hello_world.writeUTF("Hello World!");

MQPutMessageOptions pmo = new MQPutMessageOptions();

system_default_local_queue.put(hello_world,pmo);


system_default_local_queue.close();

qMgr.disconnect();
}
catch (MQException ex)
{
System.out.println("An MQSeries error occurred : Completion code " + ex.completionCode + " Reason code " + ex.reasonCode);
}

catch (java.io.IOException ex)
{
System.out.println("An error occurred whilst writing to the message buffer: " + ex);
}
}
}

------------------

You don't have to install MQ classes on the receiving QMGR.

You shouldn't specify the IP in the program. The channel definition is the place where you specify that and never in a program.

---
Venny
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Praveen
PostPosted: Mon Nov 11, 2002 12:54 am    Post subject: Reply with quote

Apprentice

Joined: 23 Oct 2002
Posts: 40
Location: Bangalore

Venny,
Thanks for your inputs. Now I am able to run my program. I had changed the openOptions=MQC.MQOO_OUTPUT, because it was giving errors (Error code:2045).
This time problem is after running the program from Win 2k machine I am trying to get the message in Sun machine by typing the following command,
amqsget RECIEVER.QUEUE
where RECIEVER.QUEUE is my reciever queue which I had defined in sun machine. Its giving the following error.
Sample AMQSGET0 start
MQGET ended with reason code 2110
message<>
no more messages
Sample AMQSGET0 end

This error code seems to be some message format error. Can you please guide me what is the problem in my code..??
_________________
Thanks,

Praveen K
Back to top
View user's profile Send private message
vennela
PostPosted: Mon Nov 11, 2002 4:09 am    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

Praveen:

You can do a couple of things here:
1. On Solaris use amqsbcg --- This is same as the other two but is used to BROWSE messages.

2. A slight change in your program

Change hello_world.writeUTF("Hello World!"); to
hello_world.writeString("Hello World as a String!");

With this change you should be able to use amqsget to get the message

---
Venny
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Praveen
PostPosted: Mon Nov 11, 2002 5:40 am    Post subject: Reply with quote

Apprentice

Joined: 23 Oct 2002
Posts: 40
Location: Bangalore

Venny,
Thats great, its working now . Thank you very much.
But still doubts..
Now I am able to send the messages and able to get the messages manually by amqsget or amqsbcg, but if I want to recieve the messages by my program only how I need to proceed??. Do I need to set a different remote definition of local queue to recieve the messages or ??. Please help me out in this. Depending on this I need to write the program for my application. If you are able to send me the steps that would be great..
_________________
Thanks,

Praveen K
Back to top
View user's profile Send private message
vennela
PostPosted: Mon Nov 11, 2002 3:57 pm    Post subject: Reply with quote

Jedi Knight

Joined: 11 Aug 2002
Posts: 4055
Location: Hyderabad, India

You are almost set. If you install the support pack MA88 on your Solaris machine where the second QMGR is you can rock n roll.
Once you install MA88 on the Sun machine you can run another Java application which will GET messages. There should be some java examples for GETting messages in the forum's repository.

I am assuming you would PUT a message on QMGR1 (on Win M/C) and GET it on QMGR2 (on Solaris ) or vice versa.

Your posts sounds like : You want to put a message on QMGR1 -> send it to QMGR2 -> Send the message back somehow to QMGR1 and then MQGET by your Java program. If this is what you are intending to do then it's like Lucius saying to Portia "Run to the Capitol, and nothing else?
And so return to you, and nothing else?"

Yes you can do this:
PUT on a remoteQ on QMGR1.
GET on QMGR2.
On QMGR2 process the message you got.
Send the response back to QMGR1.
If this is what you are trying to do then

On QMGR1:
1. Define a RemoteQ Q1 ( Destination Queue Manager QMGR2 - Transmission Queue - that you define in step 2 below )
2. Define a XMITQ to QMGR2
3. Define a Sender (SDR) channel ( from QMGR1 to QMGR2 with XMITQ defined in step 2 ).
4. A LocalQ Q2.
5. A Receiver channel ( From QMGR2 to QMGR1 ).

On QMGR2:


1. Define a RemoteQ Q2 ( Destination Queue Manager QMGR1 - Transmission Queue - that you define in step 2 below )
2. Define a XMITQ to QMGR1
3. Define a SDR channel ( from QMGR2 to QMGR1 with XMITQ defined in step 2 ).
4. A LocalQ Q1.
5. A Receiver channel ( From QMGR1 to QMGR2 ).

Now :
On QMGR1 your Java Application should PUT to Q1
On QMGR2 your Java Application should GET from Q1 and process the message and PUT to Q2.
On QMGR1 another java app should GET on Q2.

Hope it isn't too confusing.

---
Venny
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Praveen
PostPosted: Tue Nov 12, 2002 6:18 am    Post subject: Reply with quote

Apprentice

Joined: 23 Oct 2002
Posts: 40
Location: Bangalore

Venny,
I am in the process of installing MA88 on my sun machine. In the mean time I am having some of the doubts can you please suggest me on these things. Presently my application is in C++, now we are developing the whole thing in java. In my C++ application for one of the interfacing application we are using MQSeries to send and receive the data. For this there is C++ MQSeries Client program, which sends and receives the data . For this we got the MQSeries Queue Manager, Destination Queue (Remote Queue) and Reply Queue.
My question is, for java also do I need to write the separate client program or I can just write everything in a single java (As I had done in my MQSample program) program where I can specify required Environment fields and send the data to the server and receive it back in the same file.

According to my knowledge C++ is not having direct APIs to use that’s why they might have written a separate client program, but in java there are direct APIs are provided so probably we don’t need to write separate client program. Please correct me if I am wrong.


I hope I am not confusing you. Please guide me in this regard.
_________________
Thanks,

Praveen K
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 Installation/Configuration Support » Problem in sending/recieving messages from my Java program
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.