[digest infocenter]MQ2
来源:互联网 发布:数据库管理人员 编辑:程序博客网 时间:2024/06/03 13:35
Handling messages
Put messages onto queues using the put() method of the MQQueue class. You get messages from queues using the get() method of the MQQueue class. Unlike the procedural interface, where MQPUT and MQGET put and get arrays of bytes, the Java programming language puts and gets instances of the MQMessage class. The MQMessage class encapsulates the data buffer that contains the actual message data, together with all the MQMD (message descriptor) parameters that describe that message.
To build a new message, create a new instance of the MQMessage class, and use the writeXXX methods to put data into the message buffer.
When the new message instance is created, all the MQMD parameters are automatically set to their default values, as defined in the WebSphere MQ Application Programming Reference. The put() method of MQQueue also takes an instance of the MQPutMessageOptions class as a parameter. This class represents the MQPMO structure. The following example creates a message and puts it onto a queue:
// Build a new message containing my age followed by my nameMQMessage myMessage = new MQMessage();myMessage.writeInt(25); String name = "Charlie Jordan";myMessage.writeInt(name.length());myMessage.writeBytes(name); // Use the default put message options...MQPutMessageOptions pmo = new MQPutMessageOptions(); // put the message!queue.put(myMessage,pmo);The get() method of MQQueue returns a new instance of MQMessage, which represents the message just taken from the queue. It also takes an instance of the MQGetMessageOptions class as a parameter. This class represents the MQGMO structure.
You do not need to specify a maximum message size, because the get() method automatically adjusts the size of its internal buffer to fit the incoming message. Use the readXXX methods of the MQMessage class to access the data in the returned message.
Note: If you are using codepage conversion in your application you must manage your message buffer manually, not automatically. The reason for this is that the automatic buffer size is based on the unconverted message, not the converted message and might therefore be too small for the converted message, resulting in a MQRC_CONVERTED_MSG_TOO_BIG (RC=2120) error.
The following example shows how to get a message from a queue:
// Get a message from the queueMQMessage theMessage = new MQMessage();MQGetMessageOptions gmo = new MQGetMessageOptions();queue.get(theMessage,gmo); // has default values // Extract the message dataint age = theMessage.readInt();int strLen = theMessage.readInt();byte[] strData = new byte[strLen];theMessage.readFully(strData,0,strLen);String name = new String(strData,0);
You can alter the number format that the read and write methods use by setting the encoding member variable.
You can alter the character set to use for reading and writing strings by setting the characterSet member variable.
See MQMessage for more details.
Note: The writeUTF() method of MQMessage automatically encodes the length of the string as well as the Unicode bytes it contains. When your message will be read by another Java program (using readUTF()), this is the simplest way to send string information.
- [digest infocenter]MQ2
- [digest from infocenter ]Java develop MQ application 1
- IBM InfoCenter
- DB2 infocenter
- Digest
- News Digest
- News Digest
- RFC Digest
- Digest authentication
- Digest authentication
- English digest
- Ruby Digest
- digest鉴权
- angular $digest
- Digest authentication
- digest鉴权
- digest认证
- digest介绍
- C++类的实例化后占内存的大小计算
- GDB完全手册
- C++类的大小——sizeof()
- 简单Remoting例子(1)
- JQuery练习——操作Checkbox例子
- [digest infocenter]MQ2
- JDBC 连接 Oracle
- App Store (China) Largest Donload Meta Date
- Android 入门eclipse+ADT配置,bug处理及附件下载(一)
- C++多继承的细节
- C++多继承
- 具有超时限制的read调用
- stateGroups
- 写个小题目