Class MessageEnvelop

java.lang.Object
org.pipservices3.messaging.queues.MessageEnvelope

public class MessageEnvelop
extends Object
Allows adding additional information to messages. A correlation id, message id, and a message type are added to the data being sent/received. Additionally, a MessageEnvelope can reference a lock token.

Side note: a MessageEnvelope's message is stored as a buffer, so strings are converted using utf8 conversions.

  • Constructor Details

    • MessageEnvelop

      public MessageEnvelop()
      Creates a new MessageEnvelope.
    • MessageEnvelop

      public MessageEnvelop​(String correlationId, String messageType, Object message)
      Creates a new MessageEnvelop, which adds a correlation id, message id, and a type to the data being sent/received.
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      messageType - a string value that defines the message's type.
      message - the data being sent/received.
    • MessageEnvelop

      public MessageEnvelop​(String correlationId, String messageType, String message)
      Creates a new MessageEnvelop, which adds a correlation id, message id, and a type to the data being sent/received.
      Parameters:
      correlationId - (optional) transaction id to trace execution through call chain.
      messageType - a string value that defines the message's type.
      message - the data being sent/received.
  • Method Details

    • getReference

      public Object getReference()
      Returns:
      the lock token that this MessageEnvelope references.
    • setReference

      public void setReference​(Object value)
      Sets a lock token reference for this MessageEnvelope.
      Parameters:
      value - the lock token to reference.
    • getCorrelationId

      public String getCorrelationId()
    • setCorrelationId

      public void setCorrelationId​(String value)
    • getMessageId

      public String getMessageId()
    • setMessageId

      public void setMessageId​(String value)
    • getMessageType

      public String getMessageType()
    • setMessageType

      public void setMessageType​(String value)
    • getSentTime

      public ZonedDateTime getSentTime()
    • setSentTime

      public void setSentTime​(ZonedDateTime value)
    • getMessage

      public Object getMessage()
    • setMessage

      public void setMessage​(Object value)
    • setMessageAsJson

      public void setMessageAsJson​(Object message) throws com.fasterxml.jackson.core.JsonProcessingException
      Stores the given string.
      Parameters:
      message - the string to set. Will be converted to a buffer, using UTF-8 encoding.
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • getMessageAsJson

      public <T> T getMessageAsJson​(Class<T> type) throws com.fasterxml.jackson.databind.JsonMappingException, com.fasterxml.jackson.core.JsonParseException, IOException
      Returns:
      the value that was stored in this message as a JSON string.
      Throws:
      com.fasterxml.jackson.databind.JsonMappingException
      com.fasterxml.jackson.core.JsonParseException
      IOException
    • toString

      public String toString()
      Convert's this MessageEnvelope to a string, using the following format: "[correlation_id, message_type, message.toString]". If any of the values are null, they will be replaced with ---.
      Overrides:
      toString in class Object
      Returns:
      the generated string.