com.safmq
Class QueueMessage

java.lang.Object
  extended by com.safmq.QueueMessage

public class QueueMessage
extends java.lang.Object

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

QueueMessage

public QueueMessage()
Default Constructor.

Method Detail

getMessageID

public UUID getMessageID()
Provides access to the message id, this value is generated by a successful call to MQConnection.Enqueue(QueueHandle,QueueMessage).

Returns:
Returns the messageID

getBodySize

public int getBodySize()
Provides access to the size of the message body.

Returns:
Returns the bodySize.

getBufferSize

public int getBufferSize()
Provides the size of the buffer allocated.

Returns:
Returns the size of the allocated buffer.

resetBody

public void resetBody()
Resets the contents of the body.


getOutputStream

public java.io.OutputStream getOutputStream()
Provides an output stream to write data into the QueueMessage message body.

Returns:
An output stream for writing the message's body.

getInputStream

public java.io.InputStream getInputStream()
Provides an input stream to read the data in the message's body.

Returns:
An input sream to read the message's body.

getBodyType

public byte getBodyType()
The body type as set by the member setBodyType.

Returns:
Returns the bodyType.

setBodyType

public void setBodyType(byte bodyType)
Sets the message's body type.

Parameters:
bodyType - The bodyType to set.
See Also:
Safmq.BT_LONG, Safmq.BT_SHORT, Safmq.BT_CHAR, Safmq.BT_TEXT, Safmq.BT_WTEXT, Safmq.BT_BINARY, Safmq.BT_NONE

getLabel

public java.lang.String getLabel()
Provides the label of the message.

Returns:
Returns the label.

setLabel

public void setLabel(java.lang.String label)
Sets the label of the message.

Parameters:
label - The label to set.

getMessagePriority

public byte getMessagePriority()
Provides the message's priority

Returns:
Returns the messagePriority.

setMessagePriority

public void setMessagePriority(byte messagePriority)
Sets the priority of the message.

Parameters:
messagePriority - The messagePriority to set.
See Also:
Safmq.MP_STANDARD, Safmq.MP_LOW, Safmq.MP_MEDIUMLOW, Safmq.MP_MEDIUM, Safmq.MP_MEDIUMHIGH, Safmq.MP_HIGH, Safmq.MP_HIGHEST

getReciptID

public UUID getReciptID()
Provides the recipt id of this message

Returns:
Returns the recipt id.

setReciptID

public void setReciptID(UUID reciptID)
Sets the recipt id of this message

Parameters:
reciptID - The recipt id of this message

getResponseQueueName

public java.lang.String getResponseQueueName()
Provides the response queue name for this message

Returns:
Returns the name of the response queue.

setResponseQueueName

public void setResponseQueueName(java.lang.String responseQueueName)
Sets the response queue name of this message

Parameters:
responseQueueName - The name of the response queue

getTimeStamp

public long getTimeStamp()
Provides the timestamp for this message.

Returns:
Returns the time stamp.

setTimeStamp

public void setTimeStamp(long timeStamp)
Sets the timestamp for this message.

Parameters:
timeStamp - The time stamp for this message

getTimeToLiveSeconds

public int getTimeToLiveSeconds()
Provides the time to live in seconds for this message.

Returns:
Returns the timeToLiveSeconds.

setTimeToLiveSeconds

public void setTimeToLiveSeconds(int timeToLiveSeconds)
Sets the time to live in seconds for this message

Parameters:
timeToLiveSeconds - The number of seconds before this message should be purged

getTTLErrorWanted

public boolean getTTLErrorWanted()
Provids the flag indicating this message desires auto generated TTL messages.

Returns:
Returns the the flag indicating auto generated TTL messages are wanted.

setTTLErrorWanted

public void setTTLErrorWanted(boolean errorWanted)
Sets the flag indicating the auto generated TTL error message is wanted.

Parameters:
errorWanted - The flag indicating the TTL auto error message is wanted

getMessageClass

public byte getMessageClass()
Provides the message class

Returns:
Returns the message class.
See Also:
Safmq.MC_SYSTEMERRMSG, Safmq.MC_USERMSG

Copyright Matthew J. Battey, 2004-2010;
Powered By: Get SAFMQ: Store and Forward Message Queue at SourceForge.net. Fast, secure and Free Open Source software downloads