[向 大家 请教 ] 分不够提问 就90分!!! !
package com;
import com.ibm.mq.*;
/*
* 成功的访问mq 的java 类
*/
public class FirstMqTest {
// public static void main(String[] args[]){
// FirstMqTest first = new FirstMqTest();
// first.test();
// }
public static void main(String args[]){
FirstMqTest first = new FirstMqTest();
first.test();
}
public void test(){
String qManager = "P_TD_QM"; //QueueManager name
String qName = "DOWN_FROM_SA_P";//Queue Name
try {
//configure connection parameters
MQEnvironment.hostname="10.64.8.54";//MQ Server name or IP
MQEnvironment.port=1415;//listenr port
MQEnvironment.channel="CH1";//Server-Connection Channel
MQEnvironment.CCSID =819;
// 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 = MQC.MQOO_INPUT_AS_Q_DEF | MQC.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...");
/*
* 在此测试一下 mq 的传输次列
*
*/
for(int j=0;j< 5;j++){
String str ="test11111111111";
str = str+j;
msg.writeUTF(str);
queue.put(msg, pmo);
}
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) {
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);
}
}
}
--------------------------------------------------------------------------------------------------------------
以上是我以前写程序
但是 我现在发现 我门需要是用TOPIC连接方式, 而我上面的是用QUEUE连接方式, 所以 想请问一下 我需要怎么做才能用TOPIC连接 方式, 在网上都找了 N天了都没有找到 !!!!!! 还有,我感觉是不是 只有JMS才能采用TOPIC连接方式,但是我这是刚刚接受做这个IBM MQ程序 不知道 JMS该怎么做TOPIC连接,在网上看见 有的JMS程序是好象用到weblogic 而我现在是用tomcat ..... ! 疯掉了!!! 实在 希望 大家能够 指点一下 不胜感激!!!!
等会 我加分!