Class Message

java.lang.Object
com.codename1.backend.messaging.Message

public final class Message extends Object

One message: a destination, an optional key, headers, and the payload as bytes. What a listener is handed when it asks for more than the payload, and what MessageTemplate.send(Message) sends as it is.

The key is what a partitioned transport (Kafka) orders by; the others carry it as a header. Header names starting with cn1- are the runtime's own: the delivery attempt, the error a dead-lettered message failed with, and the destination it came from.

  • Field Details

    • ATTEMPT

      public static final String ATTEMPT
      The delivery attempt, counted from 1.
      See Also:
    • ERROR

      public static final String ERROR
      The text of the failure that dead-lettered a message.
      See Also:
    • ORIGIN

      public static final String ORIGIN
      The destination a dead-lettered message was sent to first.
      See Also:
    • NOT_BEFORE

      public static final String NOT_BEFORE
      The time, in epoch milliseconds, before which a retried message is not handled again.
      See Also:
    • CONTENT_TYPE

      public static final String CONTENT_TYPE
      The content type of the payload: application/json, text/plain or application/octet-stream.
      See Also:
  • Constructor Details

    • Message

      public Message(String destination, byte[] payload)
      A message to destination with no key.
    • Message

      public Message(String destination, String key, byte[] payload, Map<String,String> headers)
      A message to destination; key and headers may be null.
  • Method Details

    • getDestination

      public String getDestination()
      Where it is sent: a queue, a topic or a stream, whichever the transport has.
    • getKey

      public String getKey()
      The ordering key, or null.
    • getPayload

      public byte[] getPayload()
      The payload. Not copied; do not change it.
    • getText

      public String getText()
      The payload as UTF-8 text.
    • getHeaders

      public Map<String,String> getHeaders()
      The headers, which a listener may read but not change.
    • getHeader

      public String getHeader(String name)
      One header, or null.
    • getAttempt

      public int getAttempt()
      Which delivery of this message this is, counted from 1.
    • getId

      public String getId()
      The transport's identifier of this delivery, or null before it is sent.
    • withHeader

      public Message withHeader(String name, String value)
      A copy with name set to value, or removed when value is null.
    • to

      public Message to(String to)
      A copy sent to to instead.
    • toString

      public String toString()
      Description copied from class: Object
      Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
      Overrides:
      toString in class Object