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 » WebSphere Message Broker (ACE) Support » Integrating Java with MQ

Post new topic  Reply to topic
 Integrating Java with MQ « View previous topic :: View next topic » 
Author Message
saurabh.mk2003
PostPosted: Sun May 27, 2007 8:45 pm    Post subject: Integrating Java with MQ Reply with quote

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
View user's profile Send private message Send e-mail
marcin.kasinski
PostPosted: Sun May 27, 2007 11:09 pm    Post subject: Re: Integrating Java with MQ Reply with quote

Sentinel

Joined: 21 Dec 2004
Posts: 850
Location: Poland / Warsaw

Have you saw this ?

http://www-304.ibm.com/jct09002c/isv/tech/sampmq.html
_________________
Marcin
Back to top
View user's profile Send private message Visit poster's website
Vitor
PostPosted: Mon May 28, 2007 9:53 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

And of course this:

http://www.mqseries.net/phpBB2/viewtopic.php?t=37293

We're here to help you, not do your job for you. Unless you're providing a purchase order....
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
Gaya3
PostPosted: Mon May 28, 2007 7:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
saurabh.mk2003
PostPosted: Mon May 28, 2007 8:48 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
marcin.kasinski
PostPosted: Mon May 28, 2007 10:18 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Vitor
PostPosted: Tue May 29, 2007 12:03 am    Post subject: Reply with quote

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
View user's profile Send private message
saurabh.mk2003
PostPosted: Tue May 29, 2007 10:50 pm    Post subject: RE:Integrating Java with MQ Reply with quote

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
View user's profile Send private message Send e-mail
marcin.kasinski
PostPosted: Tue May 29, 2007 11:06 pm    Post subject: Re: RE:Integrating Java with MQ Reply with quote

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
View user's profile Send private message Visit poster's website
saurabh.mk2003
PostPosted: Wed May 30, 2007 6:04 am    Post subject: RE:Integrating Java with MQ Reply with quote

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
View user's profile Send private message Send e-mail
Vitor
PostPosted: Wed May 30, 2007 6:08 am    Post subject: Re: RE:Integrating Java with MQ Reply with quote

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
View user's profile Send private message
saurabh.mk2003
PostPosted: Fri Jun 01, 2007 10:47 pm    Post subject: Integrating Java with MQ Reply with quote

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
View user's profile Send private message Send e-mail
Vitor
PostPosted: Sat Jun 02, 2007 2:58 am    Post subject: Re: Integrating Java with MQ Reply with quote

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
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 » WebSphere Message Broker (ACE) Support » Integrating Java with MQ
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.