|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.safmq.QueueMessage
public class QueueMessage
Represents a message to be sent or retrieved from a SAFMQ message queue server.
In the simplest use of the QueueMessage
object, clients
would only need to instantiate an instance then write to the body represented
by an OutputStream
then the message could be sent to the server.
An example follows:
MessageQueue queue = MQBuilder.buildMessageQueue("//localhost/foo","user","password"); QueueMessage msg = new QueueMessage(); PrintWriter w = new PrintWriter(new OutputStreamWriter(msg.getOutputStream())); w.write("Hello World!"); w.flush(); queue.Enqueue(msg); queue.Close();
Facilitating two way communications, the QueueMessage
class
provides a facility via a "Recipt ID" in which responding programs can place
the original message's id into the recipt id of the response so that the
querier can wait for a response. Additionaly, SAFMQ provides the ability to
prescribe a "Time-To-Live" for a message query so that in the case that
the responding program is not able to retrieve the message and respond in time,
the caller can be notified by the SAFMQ server. An example follows:
The Client:
MessageQueue queue = MQBuilder.buildMessageQueue("//localhost/foo","user","password"); QueueMessage msg = new QueueMessage(); PrintWriter w = new PrintWriter(new OutputStreamWriter(msg.getOutputStream())); w.write("Hello World!"); w.flush(); msg.setLable("Query"); msg.setTimeToLiveSeconds(5); // allow 5 seconds before an auto response msg.setTTLErrorWanted(true); msg.setResponseQueueName("//localhost/foo"); if (queue.Enqueue(msg) == Safmq.EC_NOERROR) { UUID id = msg.getMessageID(); // generated via the call to Enqueue() msg = new QueueMessage(); if (queue.RetrieveID(true,id,-1,msg) == Safmq.EC_NOERROR) { if (msg.getMessageClass() == Safmq.MC_SYSTEMERRMSG) { System.out.println("The message errored out"); } InputStream in = msg.getInputStream(); byte data[] = new byte[1024]; int read; while ( (read=in.read(data)) > 0) { System.out.write(data,0,read); } } } queue.close();
The Server:
MessageQueue queue = MQBuilder.buildMessageQueue("//localhost/foo","user","password"); QueueMessage msg = new QueueMessage(); while ( queue.Retrieve(true,-1,msg) == Safmq.EC_NOERROR ) { QueueMessage response = new QueueMessage(); PrintWriter w = new PrintWriter(new OutputStreamWriter(response.getOutputStream())); w.write("Back at ya!"); w.flush(); response.setReciptID(msg.getMesasgeID()); response.setLabel("Response"); MessageQueue responseQueue = MQBuilder.buildMessageQueue(msg.getResponseQueueName(),"user","password"); responseQueue.Enqueue(response); responseQueue.Close(); msg = new QueueMessage(); } queue.Close();
Constructor Summary | |
---|---|
QueueMessage()
Default Constructor. |
Method Summary | |
---|---|
int |
getBodySize()
Provides access to the size of the message body. |
byte |
getBodyType()
The body type as set by the member setBodyType . |
int |
getBufferSize()
Provides the size of the buffer allocated. |
java.io.InputStream |
getInputStream()
Provides an input stream to read the data in the message's body. |
java.lang.String |
getLabel()
Provides the label of the message. |
byte |
getMessageClass()
Provides the message class |
UUID |
getMessageID()
Provides access to the message id, this value is generated by a successful call to MQConnection.Enqueue(QueueHandle,QueueMessage) . |
byte |
getMessagePriority()
Provides the message's priority |
java.io.OutputStream |
getOutputStream()
Provides an output stream to write data into the QueueMessage
message body. |
UUID |
getReciptID()
Provides the recipt id of this message |
java.lang.String |
getResponseQueueName()
Provides the response queue name for this message |
long |
getTimeStamp()
Provides the timestamp for this message. |
int |
getTimeToLiveSeconds()
Provides the time to live in seconds for this message. |
boolean |
getTTLErrorWanted()
Provids the flag indicating this message desires auto generated TTL messages. |
void |
resetBody()
Resets the contents of the body. |
void |
setBodyType(byte bodyType)
Sets the message's body type. |
void |
setLabel(java.lang.String label)
Sets the label of the message. |
void |
setMessagePriority(byte messagePriority)
Sets the priority of the message. |
void |
setReciptID(UUID reciptID)
Sets the recipt id of this message |
void |
setResponseQueueName(java.lang.String responseQueueName)
Sets the response queue name of this message |
void |
setTimeStamp(long timeStamp)
Sets the timestamp for this message. |
void |
setTimeToLiveSeconds(int timeToLiveSeconds)
Sets the time to live in seconds for this message |
void |
setTTLErrorWanted(boolean errorWanted)
Sets the flag indicating the auto generated TTL error message is wanted. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public QueueMessage()
Method Detail |
---|
public UUID getMessageID()
MQConnection.Enqueue(QueueHandle,QueueMessage)
.
public int getBodySize()
public int getBufferSize()
public void resetBody()
public java.io.OutputStream getOutputStream()
QueueMessage
message body.
public java.io.InputStream getInputStream()
public byte getBodyType()
setBodyType
.
public void setBodyType(byte bodyType)
bodyType
- The bodyType to set.Safmq.BT_LONG
,
Safmq.BT_SHORT
,
Safmq.BT_CHAR
,
Safmq.BT_TEXT
,
Safmq.BT_WTEXT
,
Safmq.BT_BINARY
,
Safmq.BT_NONE
public java.lang.String getLabel()
public void setLabel(java.lang.String label)
label
- The label to set.public byte getMessagePriority()
public void setMessagePriority(byte messagePriority)
messagePriority
- The messagePriority to set.Safmq.MP_STANDARD
,
Safmq.MP_LOW
,
Safmq.MP_MEDIUMLOW
,
Safmq.MP_MEDIUM
,
Safmq.MP_MEDIUMHIGH
,
Safmq.MP_HIGH
,
Safmq.MP_HIGHEST
public UUID getReciptID()
public void setReciptID(UUID reciptID)
reciptID
- The recipt id of this messagepublic java.lang.String getResponseQueueName()
public void setResponseQueueName(java.lang.String responseQueueName)
responseQueueName
- The name of the response queuepublic long getTimeStamp()
public void setTimeStamp(long timeStamp)
timeStamp
- The time stamp for this messagepublic int getTimeToLiveSeconds()
public void setTimeToLiveSeconds(int timeToLiveSeconds)
timeToLiveSeconds
- The number of seconds before this message should be purgedpublic boolean getTTLErrorWanted()
public void setTTLErrorWanted(boolean errorWanted)
errorWanted
- The flag indicating the TTL auto error message is wantedpublic byte getMessageClass()
Safmq.MC_SYSTEMERRMSG
,
Safmq.MC_USERMSG
|
Copyright Matthew J. Battey, 2004-2010; Powered By: |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |