Package org.apache.pulsar.client.api
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 TypeMethodDescription<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.intGet the number of messages when the payload is produced by Pulsar producer.getProperty(String key) Get a value associated with the given key.booleanisBatch()Check whether the payload is a batch when the payload is produced by Pulsar producer. 
- 
Method Details
- 
getProperty
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 indexnumMessages- the number of messages in the batchpayload- the message payloadcontainMetadata- whether the payload contains the single message metadataschema- the schema of the batch- Returns:
 - the created message
 
 - 
asSingleMessage
Convert the given payload to a single message if the entry is not a batch.- Type Parameters:
 T-- Parameters:
 payload- the message payloadschema- the schema of the message- Returns:
 - the created message
 
 
 -