Author |
Message
|
saurabh.mk2003 |
Posted: Sun May 27, 2007 8:45 pm Post subject: Integrating Java with MQ |
|
|
Novice
Joined: 27 May 2007 Posts: 10
|
My program requirement is that I should be able to insert or delete the messages in the Websphere Message Queue (MQ) through pure Java code . This MQ is used in the MiddleWare Technologies to read the XML file .
Then I will be using RFHUtil to check whether the message is inserted or not in the MQ.
So Could you please mail me program to do so ? |
|
Back to top |
|
 |
marcin.kasinski |
Posted: Sun May 27, 2007 11:09 pm Post subject: Re: Integrating Java with MQ |
|
|
Sentinel
Joined: 21 Dec 2004 Posts: 850 Location: Poland / Warsaw
|
|
Back to top |
|
 |
Vitor |
Posted: Mon May 28, 2007 9:53 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
|
Back to top |
|
 |
Gaya3 |
Posted: Mon May 28, 2007 7:15 pm Post subject: |
|
|
 Jedi
Joined: 12 Sep 2006 Posts: 2493 Location: Boston, US
|
Hi
Write a code in java and try to connect...
Read APG and APR PDFs for this and come up with doubts..
instead of asking the entire code.
Thanks and Regards
Gayathri _________________ Regards
Gayathri
-----------------------------------------------
Do Something Before you Die |
|
Back to top |
|
 |
saurabh.mk2003 |
Posted: Mon May 28, 2007 8:48 pm Post subject: |
|
|
Novice
Joined: 27 May 2007 Posts: 10
|
I have written the following code. Its compiling & running fine.
But its not giving its desired output.
The code is:
/*Function:
This program browses message before actually getting them.
java mqbrowse ORDER_IN */
// C:\Progra~1\Java\jdk1.6.0_01\bin\java.exe
import com.ibm.mq.*;
import java.io.*;
import java.lang.*;
public class mqbrowse
{
private MQQueueManager qMgr;
public static void main (String args[]) throws IOException
{
if (args.length < 1)
{
System.out.println("Required parameter missing - queue name");
}
else
{
System.out.println("mqbrowse: browse and optionally get messages");
mqbrowse mySample = new mqbrowse();
mySample.init();
mySample.start(args);
}
System.exit(0);
}
public void init() { }
public void start(String args[])
{
try {
if (args.length > 1)
{
qMgr = new MQQueueManager(args[1]);
}
else
{
qMgr = new MQQueueManager("");
}
int openOptions = MQC.MQOO_INPUT_EXCLUSIVE | MQC.MQOO_BROWSE;
MQQueue myQueue = qMgr.accessQueue(args[0], openOptions,null, null, null);
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String runShow;
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_FIRST;
MQMessage myMessage = new MQMessage();
boolean done = false;
do {
try {
myMessage.clearMessage();
// myMessage.correlationId = MQC.MQCI_NONE;
// myMessage.messageId = MQC.MQMI_NONE;
myQueue.get(myMessage, gmo);
String msg = myMessage.readString(myMessage.getMessageLength());
System.out.println("Browsed message: " + msg);
System.out.println("Actually get message?");
runShow = br.readLine();
if (runShow.length() > 0)
{
if ((runShow.indexOf("Y") != -1)|| (runShow.indexOf("y") != -1))
{
System.out.println("Actually getting the message");
gmo.options = MQC.MQGMO_MSG_UNDER_CURSOR;
myQueue.get(myMessage, gmo);
}
}
gmo.options = MQC.MQGMO_WAIT | MQC.MQGMO_BROWSE_NEXT;
} catch (MQException ex) {
System.out.println("MQ exception: CC = " + ex.completionCode
+ " RC = " + ex.reasonCode);
done = true;
} catch (java.io.IOException ex) {
System.out.println("Java exception: " + ex);
done = true;
}
} while (!done);
myQueue.close();
qMgr.disconnect();
}
catch (MQException ex) {
System.out.println("MQ exception: CC = " + ex.completionCode
+ " RC = " + ex.reasonCode);
}
}
}
Its ony printing 'mqbrowse: browse and optionally get messages' to the console and not browsing the message. I am not able to figure out what can I do so that it browses the messages.
Could you please help me in that? |
|
Back to top |
|
 |
marcin.kasinski |
Posted: Mon May 28, 2007 10:18 pm Post subject: |
|
|
Sentinel
Joined: 21 Dec 2004 Posts: 850 Location: Poland / Warsaw
|
Does your application printing 'mqbrowse: browse and optionally get messages' and hungs ?
Are you sure that there are messages in queue ?
Are you sure that you are browsing correct queue ?
PS. When you set MQC.MQGMO_WAIT you have to specify wait Interval. _________________ Marcin |
|
Back to top |
|
 |
Vitor |
Posted: Tue May 29, 2007 12:03 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
As a more general point, doing browse & get is a very bad idea for a number of reasons you'll find discussed at some length in the forum if you try the search button.  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
saurabh.mk2003 |
Posted: Tue May 29, 2007 10:50 pm Post subject: RE:Integrating Java with MQ |
|
|
Novice
Joined: 27 May 2007 Posts: 10
|
Yes I am sure that I am specifying the correct Queue name also there are messaes in the Queue. Its Queue depth is 12.
Its printing 'mqbrowse: browse and optionally get messages' and hungs ?
Now I am not able to figure out whats the prob?
Could you please help me in that? |
|
Back to top |
|
 |
marcin.kasinski |
Posted: Tue May 29, 2007 11:06 pm Post subject: Re: RE:Integrating Java with MQ |
|
|
Sentinel
Joined: 21 Dec 2004 Posts: 850 Location: Poland / Warsaw
|
I've tested your code.
It works.
Can you debug it and check after which line hungs ? _________________ Marcin
Last edited by marcin.kasinski on Wed May 30, 2007 6:31 am; edited 1 time in total |
|
Back to top |
|
 |
saurabh.mk2003 |
Posted: Wed May 30, 2007 6:04 am Post subject: RE:Integrating Java with MQ |
|
|
Novice
Joined: 27 May 2007 Posts: 10
|
After printing "mqbrowse: browse and optionally get messages" , its going in the start() met. Then in the start method, it is printing the reason code & Completion Code Which is there at the end.
That means it is not going in the condition block where it asks the user
whether or not to retrive the msg. |
|
Back to top |
|
 |
Vitor |
Posted: Wed May 30, 2007 6:08 am Post subject: Re: RE:Integrating Java with MQ |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
saurabh.mk2003 wrote: |
it is printing the reason code & Completion Code Which is there at the end.
|
And the reason code is....????
Which you've looked up and determined means.....??????
And as a result you've tried.....???????
And how does this square with your assertion "Its printing 'mqbrowse: browse and optionally get messages' and hungs"? Is it hanging printing the code or what? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
saurabh.mk2003 |
Posted: Fri Jun 01, 2007 10:47 pm Post subject: Integrating Java with MQ |
|
|
Novice
Joined: 27 May 2007 Posts: 10
|
While compiling & running the code as posted above, its not giving any problem. Its working fine.But on the console its giving me the MQ exception as:
MQJE001: Completion Code 2, Reason 2058
then it is going in the last catch block in the end and printing the msg :
"Rohit" which I have given just for debugging.
When I searched for this exception in Google, it states that that the Queue Manager is not connected, even though I have started the Queue Manager.
So through the same java code how can I ensure that the connection is made properly to the Queue Manager? and through which API? |
|
Back to top |
|
 |
Vitor |
Posted: Sat Jun 02, 2007 2:58 am Post subject: Re: Integrating Java with MQ |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
saurabh.mk2003 wrote: |
While compiling & running the code as posted above, its not giving any problem. |
So what you're saying is it's not giving any problem, except for the exception it's throwing?
2058 strictly means the queue manager cannot be found through any of the connection methods available. If the queue manager is running on the same machine, you've got the name wrong (perhaps the wrong case).
Another option is that it's running remotely to your Java & the client connection is incorrectly configured.
Check out the Clients for full details if that's the case. The Using Java manual also has platform specific information. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
|