Author |
Message
|
prk |
Posted: Mon Jun 05, 2006 9:26 am Post subject: MQSeries API error in Java program |
|
|
Centurion
Joined: 17 Feb 2004 Posts: 102
|
Here is my environment..
Windows 2003, MQ 5.3 CSD 09, Message Broker Toolkit 6.0
I am working on coding in Java within the EJBClient file generated using wsdl. I want to create a program which can Put and Get messages from queue parameters specified by the user and here is the code.
I am getting an error on the line ( qMgr = new MQQueueManager(qManager) ; ). When I change it to qMgr = new MQQueueManager(qManager, channel) ; I get the following error.
The constructor MQQueueManager(String, String) is undefined
Please help me, any help is greatly appreciated. Whats the correct way to resolve these errors.
----------------------------------------------------------------------------
I am importing import com.ibm.mq.*;
String hostName = "MYHOST" ;
String channel = "JAVA.CHANNEL" ;
String qManager = "MYQMGR" ;
String qName = "d_in" ;
//String connectionName = "localhost";
// Set up the MQEnvironment properties for Client Connections
MQEnvironment.hostname = hostName ;
MQEnvironment.channel = channel ;
MQEnvironment.port = 1414 ;
String connectionName="SYSTEM.DEF.SVRCONN/TCP/localhost(1414)";
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES);
// Connection To the Queue Manager
final MQQueueManager qMgr;
qMgr = new MQQueueManager(qManager) ;
//MQQueueManager qMgr=new MQQueueManager();
/* Set up the open options to open the queue for out put and
additionally we have set the option to fail if the queue manager is
quiescing.
*/
int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING ;
// Open the queue
//MQQueue queue = qMgr.accessQueue(qName, openOptions,null,null,null);
MQQueue queue = qMgr.accessQueue(qName, openOptions);
// Set the put message options , we will use the default setting.
MQPutMessageOptions pmo = new MQPutMessageOptions();
/* Next we Build a message The MQMessage class encapsulates the data buffer
that contains the actual message data, together with all the MQMD
parameters
that describe the message.
To Build a new message, create a new instance of MQMessage class and use
writxxx (we will be using writeString method). The put() method of
MQQueue also
takes an instance of the MQPutMessageOptions class as a parameter.
*/
MQMessage outMsg = new MQMessage(); //Create The message buffer
outMsg.format = MQC.MQFMT_STRING ; // Set the MQMD format field.
// Prepare message with user data
String msgString = "Test Message Using MQ Java API ";
outMsg.writeString(msgString);
// Now we put The message on the Queue
queue.put(outMsg, pmo);
// Commit the transaction.
qMgr.commit();
System.out.println(" The message has been Sussesfully put\n\n#########");
// Close the the Queue and Queue manager objects.
queue.close();
qMgr.disconnect();
|
|
Back to top |
|
 |
wschutz |
Posted: Mon Jun 05, 2006 9:46 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
Quote: |
Constructors
MQQueueManager
public MQQueueManager(String queueManagerName) throws MQException;
Creates a connection to the named queue manager.
The host name, channel name and port to use during the connection request are specified in the MQEnvironment class. This must be done before calling this constructor
|
_________________ -wayne |
|
Back to top |
|
 |
prk |
Posted: Mon Jun 05, 2006 10:15 am Post subject: |
|
|
Centurion
Joined: 17 Feb 2004 Posts: 102
|
Wayne,
I have done all the MQEnvironment stuff before the call to the constructor (shown in the code above) but I wtill get the same error. Is there anything else that I am missing. |
|
Back to top |
|
 |
wschutz |
Posted: Mon Jun 05, 2006 10:23 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
What error? This one:
Quote: |
I get the following error.
The constructor MQQueueManager(String, String) is undefined |
??
That's because you can't specify the channel name on the qmgr constructor. _________________ -wayne |
|
Back to top |
|
 |
prk |
Posted: Mon Jun 05, 2006 12:06 pm Post subject: |
|
|
Centurion
Joined: 17 Feb 2004 Posts: 102
|
You are correct Wayne, thats the error I get. If I just pass the queue manager name without channel or connection names I get lots of other errors.
Here is how I resolved the issue. I have put it in the try/catch loop and the issues is resolved. I still need to do further testing but thanks for your help. |
|
Back to top |
|
 |
8davitt |
Posted: Tue Jun 06, 2006 12:02 am Post subject: |
|
|
Apprentice
Joined: 06 Feb 2003 Posts: 37 Location: Seated in front of monitor
|
Hello prk, One thing that you should consider is which messaging API you should use. Within J2EE (EJBs) the recommended messaging API is JMS. Try to avoid using the MQ Java API in this kind of environment.
/s |
|
Back to top |
|
 |
prk |
Posted: Tue Jun 06, 2006 5:40 am Post subject: |
|
|
Centurion
Joined: 17 Feb 2004 Posts: 102
|
|
Back to top |
|
 |
|