public class ServiceBusMessage extends Object
Constructor and Description |
---|
ServiceBusMessage(AmqpMessageBody amqpMessageBody)
This constructor provides an easy way to create
ServiceBusMessage with message body as AMQP Data types
SEQUENCE and VALUE . |
ServiceBusMessage(com.azure.core.util.BinaryData body)
Creates a
ServiceBusMessage containing the body .The BinaryData provides various
convenience API representing byte array. |
ServiceBusMessage(byte[] body)
Creates a
ServiceBusMessage with given byte array body. |
ServiceBusMessage(ServiceBusReceivedMessage receivedMessage)
Creates a
ServiceBusMessage using properties from receivedMessage . |
ServiceBusMessage(String body)
Creates a
ServiceBusMessage with a UTF-8 encoded body. |
Modifier and Type | Method and Description |
---|---|
ServiceBusMessage |
addContext(String key,
Object value)
Adds a new key value pair to the existing context on Message.
|
Map<String,Object> |
getApplicationProperties()
Gets the set of free-form
ServiceBusMessage properties which may be used for passing metadata associated
with the ServiceBusMessage during Service Bus operations. |
com.azure.core.util.BinaryData |
getBody()
Gets the actual payload wrapped by the
ServiceBusMessage . |
String |
getContentType()
Gets the content type of the message.
|
String |
getCorrelationId()
Gets a correlation identifier.
|
String |
getMessageId()
Gets the message id.
|
String |
getPartitionKey()
Gets the partition key for sending a message to a partitioned entity.
|
AmqpAnnotatedMessage |
getRawAmqpMessage()
Gets the
AmqpAnnotatedMessage . |
String |
getReplyTo()
Gets the address of an entity to send replies to.
|
String |
getReplyToSessionId()
Gets or sets a session identifier augmenting the
ReplyTo address. |
OffsetDateTime |
getScheduledEnqueueTime()
Gets the scheduled enqueue time of this message.
|
String |
getSessionId()
Gets the session identifier for a session-aware entity.
|
String |
getSubject()
Gets the subject for the message.
|
Duration |
getTimeToLive()
Gets the duration before this message expires.
|
String |
getTo()
Gets the "to" address.
|
ServiceBusMessage |
setContentType(String contentType)
Sets the content type of the
ServiceBusMessage . |
ServiceBusMessage |
setCorrelationId(String correlationId)
Sets a correlation identifier.
|
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(OffsetDateTime scheduledEnqueueTime)
Sets the scheduled enqueue time of this message.
|
ServiceBusMessage |
setSessionId(String sessionId)
Sets the session identifier for a session-aware entity.
|
ServiceBusMessage |
setSubject(String subject)
Sets the subject for the message.
|
ServiceBusMessage |
setTimeToLive(Duration timeToLive)
Sets the duration of time before this message expires.
|
ServiceBusMessage |
setTo(String to)
Sets the "to" address.
|
public ServiceBusMessage(byte[] body)
ServiceBusMessage
with given byte array body.body
- The content of the Service bus message.NullPointerException
- if body
is null.public ServiceBusMessage(String body)
ServiceBusMessage
with a UTF-8
encoded body.body
- The content of the Service Bus message.NullPointerException
- if body
is null.public ServiceBusMessage(com.azure.core.util.BinaryData body)
ServiceBusMessage
containing the body
.The BinaryData
provides various
convenience API representing byte array. It also provides a way to serialize Object
into BinaryData
.body
- The data to set for this ServiceBusMessage
.NullPointerException
- if body
is null
.BinaryData
public ServiceBusMessage(AmqpMessageBody amqpMessageBody)
ServiceBusMessage
with message body as AMQP Data types
SEQUENCE
and VALUE
.
In case of SEQUENCE
, tt support sending and receiving of only one AMQP Sequence at present.
If you are sending message with single byte array or String data, you can also use other constructor.amqpMessageBody
- amqp message body.NullPointerException
- if amqpMessageBody
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
.IllegalStateException
- for invalid AmqpMessageBodyType
.public Map<String,Object> getApplicationProperties()
ServiceBusMessage
properties which may be used for passing metadata associated
with the ServiceBusMessage
during Service Bus operations. A common use-case for getApplicationProperties()
is to associate serialization hints for the ServiceBusMessage.getBody()
as an aid to consumers
who wish to deserialize the binary data.ServiceBusMessage
.public com.azure.core.util.BinaryData getBody()
ServiceBusMessage
.
The BinaryData
wraps byte array and is an abstraction over many different ways it can be represented.
It provides convenience APIs to serialize/deserialize the object.
If the means for deserializing the raw data is not apparent to consumers, a common technique is to make use
of ServiceBusMessage.getApplicationProperties()
when creating the event, to associate serialization hints as an aid to
consumers who wish to deserialize the binary data.
IllegalStateException
- if called for the messages which are not of binary data type.public String getContentType()
Optionally describes the payload of the message, with a descriptor following the format of RFC2045, Section 5, for example "application/json".
ServiceBusMessage
.public ServiceBusMessage setContentType(String contentType)
ServiceBusMessage
.
Optionally describes the payload of the message, with a descriptor following the format of RFC2045, Section 5, for example "application/json".
contentType
- RFC2045 Content-Type descriptor 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 getSubject()
This property enables the application to indicate the purpose of the message to the receiver in a standardized fashion, similar to an email subject line. The mapped AMQP property is "subject".
public ServiceBusMessage setSubject(String subject)
subject
- The application specific subject.ServiceBusMessage
object.public String getMessageId()
The message identifier is an application-defined value that uniquely identifies the message and its payload. The
identifier is a free-form string and can reflect a GUID or an identifier derived from the application context. If
enabled, the
duplicate detection
feature identifies and removes second and further submissions of messages with the same messageId
.
ServiceBusMessage
.public ServiceBusMessage setMessageId(String messageId)
messageId
- The message id to be set.ServiceBusMessage
.IllegalArgumentException
- if messageId
is too long.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
- The partition key of this message.ServiceBusMessage
.IllegalArgumentException
- if partitionKey
is too long or if the partitionKey
does not
match the sessionId
.ServiceBusMessage.getPartitionKey()
public AmqpAnnotatedMessage getRawAmqpMessage()
AmqpAnnotatedMessage
.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()
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.
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 message.ServiceBusMessage
.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 OffsetDateTime 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 datetime; the actual activation time depends on the queue's workload and its state.
public ServiceBusMessage setScheduledEnqueueTime(OffsetDateTime scheduledEnqueueTime)
null
will not be set. If this value needs to be unset
it could be done by value removing from AmqpAnnotatedMessage.getMessageAnnotations()
using key AmqpMessageConstant.SCHEDULED_ENQUEUE_UTC_TIME_NAME
.scheduledEnqueueTime
- the datetime at which this message should be enqueued in Azure Service Bus.ServiceBusMessage
.ServiceBusMessage.getScheduledEnqueueTime()
public String getReplyToSessionId()
ReplyTo
address.
This value augments the reply to
information and specifies which sessionId
should
be set for the reply when sent to the reply entity.
getReplyToGroupId
property value of this message.public ServiceBusMessage setReplyToSessionId(String replyToSessionId)
ReplyTo
address.replyToSessionId
- The ReplyToGroupId property value of this message.ServiceBusMessage
.public String getSessionId()
For session-aware entities, this application-defined value specifies the session affiliation of the message. Messages with the same session identifier are subject to summary locking and enable exact in-order processing and demultiplexing. For session-unaware entities, this value is ignored. See Message Sessions.
ServiceBusMessage
.public ServiceBusMessage setSessionId(String sessionId)
sessionId
- The session identifier to be set.ServiceBusMessage
.IllegalArgumentException
- if sessionId
is too long or if the sessionId
does not match
the partitionKey
.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 © 2021 Microsoft Corporation. All rights reserved.