public class ServiceBusMessage extends Object
Here's how AMQP message sections map to ServiceBusMessage
. For reference, the specification can be found
here:
AMQP 1.0 specification
ServiceBusMessage.getProperties()
- AMQPMessage.ApplicationProperties sectionServiceBusMessage.getBody()
- if AMQPMessage.Body has Data section
Serializing a received ServiceBusMessage
with AMQP sections other than ApplicationProperties
(with primitive Java types) and Data section is not supported.
ServiceBusMessageBatch
Constructor and Description |
---|
ServiceBusMessage(byte[] body)
Creates a
ServiceBusMessage containing the body . |
ServiceBusMessage(ServiceBusReceivedMessage receivedMessage)
Creates a
ServiceBusMessage using properties from receivedMessage . |
Modifier and Type | Method and Description |
---|---|
ServiceBusMessage |
addContext(String key,
Object value)
Adds a new key value pair to the existing context on Message.
|
byte[] |
getBody()
Gets the actual payload/data wrapped by the
ServiceBusMessage . |
String |
getContentType()
Gets the content type of the message.
|
String |
getCorrelationId()
Gets a correlation identifier.
|
String |
getLabel()
Gets the label for the message.
|
String |
getMessageId() |
String |
getPartitionKey()
Gets the partition key for sending a message to a partitioned entity.
|
Map<String,Object> |
getProperties()
Gets the set of free-form
ServiceBusMessage properties which may be used for passing metadata associated
with the ServiceBusMessage during Service Bus operations. |
String |
getReplyTo()
Gets the address of an entity to send replies to.
|
String |
getReplyToSessionId()
Gets or sets a session identifier augmenting the
ReplyTo address. |
Instant |
getScheduledEnqueueTime()
Gets the scheduled enqueue time of this message.
|
String |
getSessionId()
Gets the session id of the message.
|
Duration |
getTimeToLive()
Gets the duration before this message expires.
|
String |
getTo()
Gets the "to" address.
|
String |
getViaPartitionKey()
Gets the partition key for sending a message to a entity via another partitioned transfer entity.
|
ServiceBusMessage |
setContentType(String contentType)
Sets the content type of the
ServiceBusMessage . |
ServiceBusMessage |
setCorrelationId(String correlationId)
Sets a correlation identifier.
|
ServiceBusMessage |
setLabel(String label)
Sets the label for the message.
|
ServiceBusMessage |
setMessageId(String messageId)
Sets the message id.
|
ServiceBusMessage |
setPartitionKey(String partitionKey)
Sets a partition key for sending a message to a partitioned entity
|
ServiceBusMessage |
setReplyTo(String replyTo)
Sets the address of an entity to send replies to.
|
ServiceBusMessage |
setReplyToSessionId(String replyToSessionId)
Gets or sets a session identifier augmenting the
ReplyTo address. |
ServiceBusMessage |
setScheduledEnqueueTime(Instant scheduledEnqueueTime)
Sets the scheduled enqueue time of this message.
|
ServiceBusMessage |
setSessionId(String sessionId)
Sets the session id.
|
ServiceBusMessage |
setTimeToLive(Duration timeToLive)
Sets the duration of time before this message expires.
|
ServiceBusMessage |
setTo(String to)
Sets the "to" address.
|
ServiceBusMessage |
setViaPartitionKey(String viaPartitionKey)
Sets a via-partition key for sending a message to a destination entity via another partitioned entity
|
public ServiceBusMessage(byte[] body)
ServiceBusMessage
containing the body
.body
- The data to set for this ServiceBusMessage
.NullPointerException
- if body
is null
.public ServiceBusMessage(ServiceBusReceivedMessage receivedMessage)
ServiceBusMessage
using properties from receivedMessage
.
This is normally used when a ServiceBusReceivedMessage
needs to be sent to another entity.receivedMessage
- The received message to create new message from.NullPointerException
- if receivedMessage
is null
.public Map<String,Object> getProperties()
ServiceBusMessage
properties which may be used for passing metadata associated
with the ServiceBusMessage
during Service Bus operations. A common use-case for properties()
is
to associate serialization hints for the ServiceBusMessage.getBody()
as an aid to consumers who wish to deserialize the
binary data.ServiceBusMessage
.public byte[] getBody()
ServiceBusMessage
.
If the means for deserializing the raw data is not apparent to consumers, a common technique is to make use of
ServiceBusMessage.getProperties()
when creating the event, to associate serialization hints as an aid to consumers who
wish to deserialize the binary data.
public String getContentType()
ServiceBusMessage
.public ServiceBusMessage setContentType(String contentType)
ServiceBusMessage
.contentType
- of the message.ServiceBusMessage
.public String getCorrelationId()
Allows an application to specify a context for the message for the purposes of correlation, for example reflecting the MessageId of a message that is being replied to.
public ServiceBusMessage setCorrelationId(String correlationId)
correlationId
- correlation id of this messageServiceBusMessage
.ServiceBusMessage.getCorrelationId()
public String getLabel()
public ServiceBusMessage setLabel(String label)
label
- The label to set.ServiceBusMessage
object.public String getMessageId()
ServiceBusMessage
.public ServiceBusMessage setMessageId(String messageId)
messageId
- to be set.ServiceBusMessage
.public String getPartitionKey()
For partitioned
entities, setting this value enables assigning related messages to the same internal partition, so that
submission sequence order is correctly recorded. The partition is chosen by a hash function over this value and
cannot be chosen directly. For session-aware entities, the sessionId
property overrides
this value.
public ServiceBusMessage setPartitionKey(String partitionKey)
partitionKey
- partition key of this messageServiceBusMessage
.ServiceBusMessage.getPartitionKey()
public String getReplyTo()
This optional and application-defined value is a standard way to express a reply path to the receiver of the message. When a sender expects a reply, it sets the value to the absolute or relative path of the queue or topic it expects the reply to be sent to.
public ServiceBusMessage setReplyTo(String replyTo)
replyTo
- ReplyTo property value of this messageServiceBusMessage
.ServiceBusMessage.getReplyTo()
public String getTo()
public ServiceBusMessage setTo(String to)
This property is reserved for future use in routing scenarios and presently ignored by the broker itself. Applications can use this value in rule-driven auto-forward chaining scenarios to indicate the intended logical destination of the message.
to
- To property value of this messageServiceBusMessage
.public Duration getTimeToLive()
This value is the relative duration after which the message expires, starting from the instant the message has
been accepted and stored by the broker, as captured in ServiceBusMessage.getScheduledEnqueueTime()
. When not set
explicitly, the assumed value is the DefaultTimeToLive set for the respective queue or topic. A message-level
TimeToLive value cannot be longer than the entity's DefaultTimeToLive setting and it is silently adjusted if it
does.
public ServiceBusMessage setTimeToLive(Duration timeToLive)
timeToLive
- Time to Live duration of this messageServiceBusMessage
.ServiceBusMessage.getTimeToLive()
public Instant getScheduledEnqueueTime()
This value is used for delayed message availability. The message is safely added to the queue, but is not considered active and therefore not retrievable until the scheduled enqueue time. Mind that the message may not be activated (enqueued) at the exact given instant; the actual activation time depends on the queue's workload and its state.
public ServiceBusMessage setScheduledEnqueueTime(Instant scheduledEnqueueTime)
scheduledEnqueueTime
- the instant at which this message should be enqueued in Azure Service Bus.ServiceBusMessage
.ServiceBusMessage.getScheduledEnqueueTime()
public String getReplyToSessionId()
ReplyTo
address.
This value augments the ReplyTo information and specifies which SessionId should be set for the reply when sent to the reply entity.
public ServiceBusMessage setReplyToSessionId(String replyToSessionId)
ReplyTo
address.replyToSessionId
- ReplyToSessionId property value of this messageServiceBusMessage
.public String getViaPartitionKey()
ServiceBusMessage.getPartitionKey()
and ensures that
messages are kept together and in order as they are transferred.public ServiceBusMessage setViaPartitionKey(String viaPartitionKey)
viaPartitionKey
- via-partition key of this messageServiceBusMessage
.ServiceBusMessage.getViaPartitionKey()
public String getSessionId()
ServiceBusMessage
.public ServiceBusMessage setSessionId(String sessionId)
sessionId
- to be set.ServiceBusMessage
.public ServiceBusMessage addContext(String key, Object value)
key
- The key for this context objectvalue
- The value for this context object.ServiceBusMessage
.NullPointerException
- if key
or value
is null.Copyright © 2020 Microsoft Corporation. All rights reserved.