Reputation: 311
This code sends the message to Q. MQEnvironment static values are set . But MQEnvironment is not referenced anywhere in the manager. Then how the properties (hostname, channel,port,CCSID) are provided to connect to MQ?
MQEnvironment.hostname ="10.XX.XXX.XX";
MQEnvironment.channel = "SYSTEM.DEF.SVRCONN";
MQEnvironment.port = 1415;
MQEnvironment.CCSID = 819;
System.out.println("connecting MQQueueManager...");
try {
MQQueueManager manager = new MQQueueManager("SXX");
MQQueue queue = null;
int openOptions = MQC.MQOO_OUTPUT; //MQC.MQOO_INPUT_AS_Q_DEF |
queue = manager.accessQueue("Q_NAME",
openOptions,
null, null, null);
// send message
MQMessage sendMessage = new MQMessage();
sendMessage.writeObject("TEST MESSAGE@@@@@@@@@@@@@@@@@");
MQPutMessageOptions pmo = new MQPutMessageOptions();
queue.put(sendMessage, pmo);
Upvotes: 3
Views: 6647
Reputation: 772
MQEnvironment has public static class variables (kind of global constants). The MQQueueManager object uses these values if they are set.
http://pic.dhe.ibm.com/infocenter/wmqv7/v7r0m0/index.jsp?topic=%2Fcom.ibm.mq.java.doc%2Fcom%2Fibm%2Fmq%2FMQEnvironment.html
Upvotes: 1
Reputation: 7476
The MQQueueManager object checks to see if those values have been set in the MQEnvironment class before it makes a connection to the queue manager.
Also, do NOT use the SYSTEM.DEF.SVRCONN channel as (1) it is against best practices and (2) it is a SYSTEM object that is ONLY to be used by the queue manager. Simply create or have the MQAdmin create a SVRCONN channel for you. i.e. TEST.CHL
Upvotes: 3