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 API 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: Fri Jun 01, 2007 11:16 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 browse the messages in the Websphere Message Queue (MQ) through pure Java code for which I have written the following code :

/*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.start(args);
}
System.exit(0);
}


public void start(String args[])
{
try
{
if (args.length > 1)
{

qMgr = new MQQueueManager(args[1]); //Create a connection to the queue manager.

}
else
{

qMgr = new MQQueueManager("QM"); //If the queue manager name is left blank (null or ""), a connection is made to the default queue manager
}
int openOptions = MQC.MQOO_INPUT_EXCLUSIVE | MQC.MQOO_BROWSE;
//Open to get messages with exclusive access //Open to browse message.

// MQQueue myQueue = qMgr.accessQueue(args[0], openOptions,null, null, null);
MQQueue myQueue = qMgr.accessQueue("ORDER_IN", openOptions,"QM", null, null);
//Establishes access to a WebSphere MQ queue on this queue manager to get or browse messages,




InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);




String runShow;

MQGetMessageOptions gmo = new MQGetMessageOptions();



gmo.options = MQC.MQGMO_BROWSE_FIRST; //MQC.MQGMO_WAIT |
//Browse from start of queue.



MQMessage myMessage = new MQMessage();



boolean done = true; //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);


}
}
}


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

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
Michael Dag
PostPosted: Fri Jun 01, 2007 11:50 pm    Post subject: Reply with quote

Jedi Knight

Joined: 13 Jun 2002
Posts: 2607
Location: The Netherlands (Amsterdam)

use: mqrc 2058 you will see the QmgrName is in error,
when looking at your code (and I don't know java!) it looks like you got your args mixed up... and connecting to the queuename as the queuemanager...
_________________
Michael



MQSystems Facebook page
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
marcin.kasinski
PostPosted: Fri Jun 01, 2007 11:51 pm    Post subject: Re: Integrating Java with MQ Reply with quote

Sentinel

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

2058 = MQRC Q MGR NAME ERROR
_________________
Marcin
Back to top
View user's profile Send private message Visit poster's website
jsware
PostPosted: Sat Jun 02, 2007 1:27 am    Post subject: Re: Integrating Java with MQ Reply with quote

Chevalier

Joined: 17 May 2001
Posts: 455

saurabh.mk2003 wrote:

Code:
 if (args.length > 1)
  {
    qMgr = new MQQueueManager(args[1]); //Create a connection to the queue manager.
  } else {
    qMgr = new MQQueueManager("QM");        //If the queue manager name is left blank (null or ""), a connection is made to the default 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?
Why if you do not provide args[1] do you attempt to connect to "QM". This would only work if your qmgr was called "QM".

I would make args[1] mandatory so that you have to specify it. Don't rely on default qmgrs. Always specify a qmgr name as a parameter to your program (or in a config file or some such).
_________________
Regards
John
The pain of low quaility far outlasts the joy of low price.
Back to top
View user's profile Send private message
Vitor
PostPosted: Sat Jun 02, 2007 3:01 am    Post subject: Reply with quote

Grand High Poobah

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

See also:

http://www.mqseries.net/phpBB2/viewtopic.php?t=37294&highlight=

Again I repeat that browsing then reading is a bad idea.
_________________
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 » IBM MQ API 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.