Apache Qpid : Message API Design
This page last changed on Aug 15, 2007 by rajith.
Message API DesignThis document describes the new message API for the restructured client.
Sending MessagesThe Session class provides the following methods to send messages. public interface Session{ ......... //Option1 - for small messages public void messageTransfer(String destination, Message msg, short confirmMode, short acquireMode)throws IOException; //Option2 - for large messages public void messageStream(String destination, Message msg, short confirmMode, short acquireMode)throws IOException; //Option3 - can use it with any message size, recomended for large messages public void messageTransfer(String destination, short confirmMode, short acquireMode); public void headers(Struct... headers); public void data(byte[] data); public void data(ByteBuffer buf); public void data(String str); public void endData(); ......... } Sending small MessagesOption1 provides a convinience method to send small messages. Sending large MessagesYou have two options for sending large messages, using either pull style or push style semantics Using the Session class methods (Option3)Option3 provides a more natural AMQP style set of methods Using Option2 (pull style)The messageStream method will pull data from the message and stream using the methods defined in option3.
Receiving MessagesTo receive messages you can subscribe using the following method public interface Session{ ......... public void messageSubscribe(String queue, String destination, short confirmMode, short acquireMode, MessagePartListener listener, Map<String, ?> filter, Option... options); ----- } The API provides support for receiving messages in parts as and when they arrive using the MessagePartListener. public interface MessagePartListener{ public void messageTransfer(long transferId); public void messageHeaders(Struct... headers); public void data(ByteBuffer src); public void messageReceived(); } The messageTransfer method signals the start of a transfer and passes the transferId.
The data method will be called each time Frame arrives. The messageReceived method will signal the end of the message. Consuming small messagesThe API also provides a convinient way for consuming small messages through the MessageListener interface and the MessagePartListenerAdapter. public interface MessageListener{ public void onMessage(Message message); } you can use it the following way. .........
MessageListener myMessageListener ....
session.messageSubscribe(....,new MessagePartListenerDapter(myMessageListener),...);
-----
Message abstractionMessage Interface provides an abstraction for creating messages from different data streams. public interface Message{ public MessageProperties getMessageProperties(); public DeliveryProperties getDeliveryProperties(); public void appendData(byte[] src) throws IOException; public void appendData(ByteBuffer src) throws IOException; public void readData(byte[] target) throws IOException; public ByteBuffer readData() throws IOException; public void clearData(); public long getMessageTransferId(); } |
Document generated by Confluence on Apr 22, 2008 02:47 |