Interface MessageSpecBuilder<T>
- Type Parameters:
T
- the message payload type
MessageSpec
.-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Builds theMessageSpec
.correlationMetadata
(Object correlationMetadata) Attach a correlation metadata to the message spec to be able to correlate a sending operation and the sending operation result.deliverAfter
(long delay, TimeUnit unit) Request to deliver the message only after the specified relative delay.deliverAt
(long timestamp) Deliver the message only at or after the specified absolute timestamp.Disable geo-replication for this message.eventTime
(long timestamp) Set the event time for a given message.Sets the key of the message for routing policy.keyBytes
(byte[] key) Sets the bytes of the key of the message for routing policy.orderingKey
(byte[] orderingKey) Sets the ordering key of the message for message dispatch inSubscriptionType.Key_Shared
mode.properties
(Map<String, String> properties) Add all the properties in the provided map.Sets a new property on a message.replicationClusters
(List<String> clusters) Override the geo-replication clusters for this message.sequenceId
(long sequenceId) Specify a custom sequence id for the message being published.Set a domain object on the message.
-
Method Details
-
key
Sets the key of the message for routing policy.- Parameters:
key
- the partitioning key for the message- Returns:
- the message builder instance
-
keyBytes
Sets the bytes of the key of the message for routing policy. Internally the bytes will be base64 encoded.- Parameters:
key
- routing key for message, in byte array form- Returns:
- the message builder instance
-
orderingKey
Sets the ordering key of the message for message dispatch inSubscriptionType.Key_Shared
mode. Partition key Will be used if ordering key not specified.- Parameters:
orderingKey
- the ordering key for the message- Returns:
- the message builder instance
-
value
Set a domain object on the message.- Parameters:
value
- the domain object- Returns:
- the message builder instance
-
property
Sets a new property on a message.- Parameters:
name
- the name of the propertyvalue
- the associated value- Returns:
- the message builder instance
-
properties
Add all the properties in the provided map.- Parameters:
properties
- properties to use- Returns:
- the message builder instance
-
eventTime
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.
- Parameters:
timestamp
- event timestamp (milliseconds since epoch)- Returns:
- the message builder instance
-
sequenceId
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:
sequenceId >= 0
- Sequence id for a message needs to be greater than sequence id for earlier
messages:
sequenceId(N+1) > sequenceId(N)
- 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.
- Parameters:
sequenceId
- the sequence id to assign to the current message- Returns:
- the message builder instance
-
replicationClusters
Override the geo-replication clusters for this message.- Parameters:
clusters
- the list of clusters.- Returns:
- the message builder instance
-
disableReplication
MessageSpecBuilder<T> disableReplication()Disable geo-replication for this message.- Returns:
- the message builder instance
-
deliverAt
Deliver the message only at or after the specified absolute timestamp.The timestamp is milliseconds and based on UTC (eg:
System.currentTimeMillis()
).Note: messages are only delivered with delay when a consumer is consuming through a
SubscriptionType.Shared
subscription. With other subscription types, the messages will still be delivered immediately.- Parameters:
timestamp
- absolute timestamp indicating when the message should be delivered to consumers- Returns:
- the message builder instance
-
deliverAfter
Request to deliver the message only after the specified relative delay.Note: messages are only delivered with delay when a consumer is consuming through a
SubscriptionType.Shared
subscription. With other subscription types, the messages will still be delivered immediately.- Parameters:
delay
- the amount of delay before the message will be deliveredunit
- the time unit for the delay- Returns:
- the message builder instance
-
correlationMetadata
Attach a correlation metadata to the message spec to be able to correlate a sending operation and the sending operation result.- Parameters:
correlationMetadata
- the correlation metadata to attach- Returns:
- the message builder instance
-
build
MessageSpec<T> build()Builds theMessageSpec
.- Returns:
- the built message spec
-