首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

向WebSphere mq topic中put讯息

2012-08-14 
向WebSphere mq topic中put消息package com.quest.testimport java.io.IOExceptionimport com.ibm.mq.MQ

向WebSphere mq topic中put消息

package com.quest.test;import java.io.IOException;import com.ibm.mq.MQException;import com.ibm.mq.MQGetMessageOptions;import com.ibm.mq.MQMessage;import com.ibm.mq.MQPutMessageOptions;import com.ibm.mq.MQQueueManager;import com.ibm.mq.MQTopic;import com.ibm.mq.constants.CMQC;import com.quest.mq.MQTool;public class MQTest {/** * @param args * @throws MQException  * @throws IOException  * @throws InterruptedException  */public static void main(String[] args) throws MQException, IOException, InterruptedException {String queueManagerName = "QM1";String hostname = "127.0.0.1";int port = 1421;String channel = "SYSTEM.DEF.SVRCONN";MQTool mqTool = new MQTool(queueManagerName, hostname, port, channel);MQQueueManager queueManager = mqTool.getQueueManager();//accessTopic方法的第一个参数为topic string,第二个参数为topic name  //程序会根据topic name的topic string 和你提供的topic string 组合得到消息发送到的topic stringMQTopic topic = queueManager.accessTopic("", "a", CMQC.MQTOPIC_OPEN_AS_PUBLICATION, CMQC.MQOO_OUTPUT);System.out.println(topic.getName());MQMessage msg = new MQMessage();msg.writeString("ssssssssss");MQPutMessageOptions pmo = new MQPutMessageOptions();pmo.options = CMQC.MQPMO_ASYNC_RESPONSE;topic.put(msg,pmo);System.out.println(queueManager.getAsyncStatus().putSuccessCount);System.out.println(queueManager.getAsyncStatus().putFailureCount);queueManager.commit();topic.close();MQTopic topic2 = queueManager.accessTopic("price", "", CMQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, CMQC.MQSO_CREATE);                MQGetMessageOptions option = new MQGetMessageOptions();        topic2.get(msg, option); }}

??

热点排行