往Websphere MQ 本地队列中 放入消息和获取消息
在访问一个队列首先需要获取队列管理器对象,
?
需要提供如下属性信息, 如: 队列管理器名称,端口号,服务通道,主机名称,通过这些属性就能获取队列管理器,
然后通过队列管理器 访问队列,
放入消息 即可。 最后,关闭队列。
?
下面是一个把消息 放入 WebSphere MQ 本地队列中 程序代码:
?
建立一个QueueManagerEntity实体:
如下:
public boolean sendMessage(MQQueueManager queueManager,QueueManagerEntity queueManagerEntity) throws IOException{boolean bol = false;int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE;if(queueManager==null || !queueManager.isConnected()){queueManager = getMQueueManager(queueManagerEntity);}MQQueue mqQueue = null;try {mqQueue = queueManager.accessQueue(queueManagerEntity.getQueueName(), openOptions,null,null,null);MQMessage mqMessage = new MQMessage();mqMessage.writeUTF("Hello World!!!");MQPutMessageOptions mqPutMessageOptions = new MQPutMessageOptions();//往队列中放入消息;mqQueue.put(mqMessage, mqPutMessageOptions);mqQueue.close();bol = true;} catch (MQException e) {// TODO Auto-generated catch blocke.printStackTrace();bol = false;}return bol;}
?
?