Interface MessagePayloadContext


public interface MessagePayloadContext
The context of the message payload, which usually represents a batched message (batch) or a single message.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> Message<T>
    asSingleMessage(MessagePayload payload, Schema<T> schema)
    Convert the given payload to a single message if the entry is not a batch.
    <T> Message<T>
    getMessageAt(int index, int numMessages, MessagePayload payload, boolean containMetadata, Schema<T> schema)
    Get the internal single message with a specific index from a payload if the payload is a batch.
    int
    Get the number of messages when the payload is produced by Pulsar producer.
    Get a value associated with the given key.
    boolean
    Check whether the payload is a batch when the payload is produced by Pulsar producer.
  • Method Details

    • getProperty

      String getProperty(String key)
      Get a value associated with the given key. When the message payload is not produced by Pulsar producer, a specific property is usually added to indicate the format. So this method is useful to determine whether the payload is produced by Pulsar producer.
      Parameters:
      key -
      Returns:
      the value associated with the key or null if the key or value doesn't exist
    • getNumMessages

      int getNumMessages()
      Get the number of messages when the payload is produced by Pulsar producer.
      Returns:
      the number of messages
    • isBatch

      boolean isBatch()
      Check whether the payload is a batch when the payload is produced by Pulsar producer.
      Returns:
      true if the payload is a batch
    • getMessageAt

      <T> Message<T> getMessageAt(int index, int numMessages, MessagePayload payload, boolean containMetadata, Schema<T> schema)
      Get the internal single message with a specific index from a payload if the payload is a batch.
      Type Parameters:
      T -
      Parameters:
      index - the batch index
      numMessages - the number of messages in the batch
      payload - the message payload
      containMetadata - whether the payload contains the single message metadata
      schema - the schema of the batch
      Returns:
      the created message
    • asSingleMessage

      <T> Message<T> asSingleMessage(MessagePayload payload, Schema<T> schema)
      Convert the given payload to a single message if the entry is not a batch.
      Type Parameters:
      T -
      Parameters:
      payload - the message payload
      schema - the schema of the message
      Returns:
      the created message