Websphere MQ 教程之Hello world
来源:互联网 发布:淘宝嘉年华公告是什么 编辑:程序博客网 时间:2024/05/18 09:51
本教程系原创。
大纲:
- Creating the queue manager
- Creating the local queue
- Putting a test message on the local queue
- Verifying that the test message was sent
1.Creating the queue manager using WebSphere MQ Explorer
- Start WebSphere MQ Explorer.
- In the Navigator view, right-click theQueue Managers folder, then click . TheCreate Queue Manager wizard opens.
- In the Queue Manager name field, typeQM_APPLE.
- Select the Make this the default queue manager check box.
- Click Next twice to go to Step 3 of the wizard.
- Ensure that Auto Start Queue Manager is selected.
- Click Next to go to Step 4 of the wizard.
- Ensure that the Create listener configured for TCP/IP check box is selected.
- If the Finish button is not available, type another port number in theListen on port number field. If the current value is 1414, try typing1415 or 1416.
- Click Finish.
Results
An icon representing this queue manager is displayed in the Queue Managers folder in the Navigator view of WebSphere MQ Explorer, and the queue manager automatically starts running after you create it, as shown in the following screen capture:Creating the queue manager using MQSC
About this task
Open a command prompt, and follow these steps:Results
You have now created a queue manager with the name QM_APPLE. The next task is to create a local queue that this queue manager will manage.2.Creating the local queue using WebSphere MQ Explorer
- In the Navigator view, expand theQueue Managers folder.
- Expand queue manager QM_APPLE.
- Right click the Queues folder, then click The New Local Queue wizard opens.
- In the Name field, typeQ1
- Click Finish.
Results
The new queue, Q1, is displayed in the Content view, as displayed in the following screen capture:If the queue is not displayed in the Content view, click Refresh at the top of theContent view.
Creating the local queue using MQSC
About this task
Open a command prompt and follow these steps:Results
You have now created a local queue called Q1. The next task is to put a test message to this newly created local queue.
3.Putting a test message on the queue using WebSphere MQ Explorer
在Eclipse 中,创建如下类:
package com.ibm.test;import java.io.IOException;import com.ibm.mq.MQC;import com.ibm.mq.MQException;import com.ibm.mq.MQGetMessageOptions;import com.ibm.mq.MQMessage;import com.ibm.mq.MQPutMessageOptions;import com.ibm.mq.MQQueue;import com.ibm.mq.MQQueueManager;public class MQSample {//定义队列管理器和队列的名称 private static String qmName; private static String qName; /** * @param args */public static void main(String[] args) { qmName ="QM_APPLE"; qName = "Q1"; System.out.println("QManager:"+qmName); System.out.println("QueueName:"+qName); try { //定义并初始化队列管理器对象并连接 MQQueueManager qMgr = new MQQueueManager(qmName); // 设置将要连接的队列属性 // Note. All WebSphere MQ Options are prefixed with MQC in Java. @SuppressWarnings("deprecation")int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT; //连接队列 MQQueue localQ = qMgr.accessQueue(qName, openOptions); //定义一个简单的消息 MQMessage putMessage = new MQMessage(); putMessage.writeUTF("Hello World!"); //设置写入消息的属性(默认属性) MQPutMessageOptions pmo = new MQPutMessageOptions(); //将消息写入队列 localQ.put(putMessage,pmo); // MQMessage retrievedMessage = new MQMessage();// retrievedMessage.messageId = putMessage.messageId; //// //设置取出消息的属性(默认属性)// MQGetMessageOptions gmo = new MQGetMessageOptions(); //// // 从队列中取出消息// localQ.get(retrievedMessage, gmo); // String msgText = retrievedMessage.readUTF();// System.out.println("The message is: " + msgText); //关闭队列 localQ.close(); //从队列管理器断开 qMgr.disconnect(); }catch (MQException ex) { System.out.println("A WebSphere MQ error occurred : Completion code " + ex.completionCode + " Reason code " + ex.reasonCode); }catch (IOException ex) { System.out.println("An error occurred whilst writing to the message buffer: " + ex); }catch(Exception ex){ ex.printStackTrace(); }}}编译时需要添加Websphere MQ相关类。
4.Verifying that the test message was sent using WebSphere MQ Explorer
- In the Navigator view, expand theQueue Managers folder, then expand QM_APPLE.
- Click the Queues folder.
- In the Content view, right-clickQ1, then click Browse Messages.... TheMessage browser opens to show the list of the messages that are currently onQ1.
- Double-click the last message to open its properties dialog.
Results
On the Data page of the properties dialog, the Message data field displays the content of the message in human-readable form, as shown in the following screen capture:Verifying that the test message was sent using MQSC
About this task
The amqsget sample program is used to get the message back from the queue.Open a command prompt and follow these steps:
Start the amqsget sample program:
- On Windows®, type the following command:amqsget Q1
- On Linux®, change to the /opt/mqm/samp/bin directory and type the following command:./amqsget Q1
Results
The sample program starts, and your message is displayed along with any other messages on this queue. After a pause of 15 seconds, the sample ends and the command prompt is displayed again.
Congratulations! You have now completed this tutorial.
- Websphere MQ 教程之Hello world
- Websphere MQ对象之队列
- Websphere mq对象之通道
- 系列教程:WebSphere MQ 认证考试准备
- android--Hello,World教程
- kettle Hello World教程
- WebSphere MQ
- WebSphere MQ
- Websphere MQ
- WebSphere MQ
- websphere mq
- Websphere编程之路--MQ编程初探
- Websphere编程之路--MQ编程初探
- Websphere mq对象之队列管理器
- H5B之2客户端移动Hello World教程
- H5B之3客户端Web Hello World教程
- H5B之4服务器端移动Hello World教程
- H5B之5服务器端Web Hello World教程
- 非人民币玩家一些小技巧
- Eclipse 在开发中使用到的快捷键
- android 多媒体系统梳理
- luvcview摄像头程序到Cortex A8的安装移植
- TCP/IP系列之传输层UDP协议
- Websphere MQ 教程之Hello world
- UVa 10714 - Ants
- hdu HDU Today(跑的太慢了!什么情况?优先队列优化之后也那么慢!二百多怎么跑的?)
- (iPhone/iPad开发)待解决问题
- CELL (华表)组件的Property属性
- java的JDBC编程及事务(oracle)
- 索引优化时要注意的问题
- JavaScript数组和Join()
- 一些不理解的地方