Class MessageBuilderImpl

java.lang.Object
org.apache.pulsar.client.impl.MessageBuilderImpl
All Implemented Interfaces:
MessageBuilder

public class MessageBuilderImpl extends Object implements MessageBuilder
  • Constructor Details

    • MessageBuilderImpl

      public MessageBuilderImpl()
  • Method Details

    • build

      public org.apache.pulsar.client.api.Message<byte[]> build()
      Description copied from interface: MessageBuilder
      Finalize the immutable message.
      Specified by:
      build in interface MessageBuilder
      Returns:
      a Message ready to be sent through a Producer
    • setContent

      public MessageBuilder setContent(byte[] data)
      Description copied from interface: MessageBuilder
      Set the content of the message.
      Specified by:
      setContent in interface MessageBuilder
      Parameters:
      data - array containing the payload
    • setContent

      public MessageBuilder setContent(byte[] data, int offet, int length)
      Description copied from interface: MessageBuilder
      Set the content of the message.
      Specified by:
      setContent in interface MessageBuilder
      Parameters:
      data - array containing the payload
      offet - offset into the data array
      length - length of the payload starting from the above offset
    • setContent

      public MessageBuilder setContent(ByteBuffer buf)
      Description copied from interface: MessageBuilder
      Set the content of the message.
      Specified by:
      setContent in interface MessageBuilder
      Parameters:
      buf - a ByteBuffer with the payload of the message
    • setProperties

      public MessageBuilder setProperties(Map<String,String> properties)
      Description copied from interface: MessageBuilder
      Add all the properties in the provided map.
      Specified by:
      setProperties in interface MessageBuilder
    • setProperty

      public MessageBuilder setProperty(String name, String value)
      Description copied from interface: MessageBuilder
      Sets a new property on a message.
      Specified by:
      setProperty in interface MessageBuilder
      Parameters:
      name - the name of the property
      value - the associated value
    • setKey

      public MessageBuilder setKey(String key)
      Description copied from interface: MessageBuilder
      Sets the key of the message for routing policy.
      Specified by:
      setKey in interface MessageBuilder
    • setEventTime

      public MessageBuilder setEventTime(long timestamp)
      Description copied from interface: MessageBuilder
      Set the event time for a given message.

      Applications can retrieve the event time by calling Message.getEventTime().

      Note: currently pulsar doesn't support event-time based index. so the subscribers can't seek the messages by event time.

      Specified by:
      setEventTime in interface MessageBuilder
    • setSequenceId

      public MessageBuilder setSequenceId(long sequenceId)
      Description copied from interface: MessageBuilder
      Specify a custom sequence id for the message being published.

      The sequence id can be used for deduplication purposes and it needs to follow these rules:

      1. sequenceId >= 0
      2. Sequence id for a message needs to be greater than sequence id for earlier messages: sequenceId(N+1) > sequenceId(N)
      3. It's not necessary for sequence ids to be consecutive. There can be holes between messages. Eg. the sequenceId could represent an offset or a cumulative size.
      Specified by:
      setSequenceId in interface MessageBuilder
      Parameters:
      sequenceId - the sequence id to assign to the current message
    • setReplicationClusters

      public MessageBuilder setReplicationClusters(List<String> clusters)
      Description copied from interface: MessageBuilder
      Override the replication clusters for this message.
      Specified by:
      setReplicationClusters in interface MessageBuilder
    • disableReplication

      public MessageBuilder disableReplication()
      Description copied from interface: MessageBuilder
      Disable replication for this message.
      Specified by:
      disableReplication in interface MessageBuilder