I'm very new to ibm mq, I find out the documents or books related to mb are so few, the only one I found is 'WebSphere MQ Using Java' written in 2004. But the real world has changed a lot. I installed and verified mq server 7.5 on redhat linux 64 bit successfully according to this
I also created queue manager myqm1
, queue LQ.TEST
, channel JAVA.CHANNEL
and did some test through command lines on server to ensure they work well. However when I installed a mq client on windows xp and wrote below java code, it always throw a exception:com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2035'
my code:
import com.ibm.mq.*; import com.ibm.mq.constants.MQConstants;
/** * Simple example program */ public class MQSample {
// code identifier static final String sccsid = "@(#) MQMBID sn=p000-L120604 su=_H-IvIK4nEeGko6IWl3MDhA pn=MQJavaSamples/wmqjava/MQSample.java"; // define the name of the QueueManager private static final String qManager = "myqm1"; // and define the name of the Queue private static final String qName = "LQ.TEST"; /** * Main entry point * * @param args - command line arguments (ignored) */ public static void main(String args[]) { try { MQEnvironment.hostname = "58.2.221.196"; MQEnvironment.channel = "JAVA.CHANNEL"; MQEnvironment.port = 1414; MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES); MQEnvironment.userID = "mqm"; MQEnvironment.password = "mqm"; MQEnvironment.CCSID = 1208; // Create a connection to the QueueManager System.out.println("Connecting to queue manager: " + qManager); MQQueueManager qMgr = new MQQueueManager(qManager); // Set up the options on the queue we wish to open int openOptions = MQConstants.MQOO_INPUT_AS_Q_DEF | MQConstants.MQOO_OUTPUT; // Now specify the queue that we wish to open and the open options System.out.println("Accessing queue: " + qName); MQQueue queue = qMgr.accessQueue(qName, openOptions); // Define a simple WebSphere MQ Message ... MQMessage msg = new MQMessage(); // ... and write some text in UTF8 format msg.writeUTF("Hello, World!"); // Specify the default put message options MQPutMessageOptions pmo = new MQPutMessageOptions(); // Put the message to the queue System.out.println("Sending a message..."); queue.put(msg, pmo); // Now get the message back again. First define a WebSphere MQ // message // to receive the data MQMessage rcvMessage = new MQMessage(); // Specify default get message options MQGetMessageOptions gmo = new MQGetMessageOptions(); // Get the message off the queue. System.out.println("...and getting the message back again"); queue.get(rcvMessage, gmo); // And display the message text... String msgText = rcvMessage.readUTF(); System.out.println("The message is: " + msgText); // Close the queue System.out.println("Closing the queue"); queue.close(); // Disconnect from the QueueManager System.out.println("Disconnecting from the Queue Manager"); qMgr.disconnect(); System.out.println("Done!"); } catch (MQException ex) { ex.printStackTrace(); System.out.println("A WebSphere MQ Error occured : Completion Code " + ex.completionCode + " Reason Code " + ex.reasonCode); } catch (java.io.IOException ex) { System.out.println("An IOException occured whilst writing to the message buffer: " + ex); } return; } }
Can anybody throw a light to me on that? I'm totally down.
NOT AUTHORIZED
– beny23com.ibm.mq.MQException: MQJE001: Completion Code '2', Reason '2035'
? – home