Class ServiceBusMessage
-
Constructor Summary
ConstructorDescriptionServiceBusMessage
(byte[] body) Creates aServiceBusMessage
with given byte array body.ServiceBusMessage
(com.azure.core.amqp.models.AmqpMessageBody amqpMessageBody) This constructor provides an easy way to createServiceBusMessage
with message body as AMQP Data typesSEQUENCE
andVALUE
.ServiceBusMessage
(com.azure.core.util.BinaryData body) Creates aServiceBusMessage
containing thebody
.TheBinaryData
provides various convenience API representing byte array.ServiceBusMessage
(ServiceBusReceivedMessage receivedMessage) Creates aServiceBusMessage
using properties fromreceivedMessage
.ServiceBusMessage
(String body) Creates aServiceBusMessage
with aUTF-8
encoded body. -
Method Summary
Modifier and TypeMethodDescriptionaddContext
(String key, Object value) Adds a new key value pair to the existing context on Message.Gets the set of free-formServiceBusMessage
properties which may be used for passing metadata associated with theServiceBusMessage
during Service Bus operations.com.azure.core.util.BinaryData
getBody()
Gets the actual payload wrapped by theServiceBusMessage
.Gets the content type of the message.Gets a correlation identifier.Gets the message id.Gets the partition key for sending a message to a partitioned entity.com.azure.core.amqp.models.AmqpAnnotatedMessage
Gets theAmqpAnnotatedMessage
.Gets the address of an entity to send replies to.Gets or sets a session identifier augmenting theReplyTo
address.Gets the scheduled enqueue time of this message.Gets the session identifier for a session-aware entity.Gets the subject for the message.Gets the duration before this message expires.getTo()
Gets the "to" address.setContentType
(String contentType) Sets the content type of theServiceBusMessage
.setCorrelationId
(String correlationId) Sets a correlation identifier.setMessageId
(String messageId) Sets the message id.setPartitionKey
(String partitionKey) Sets a partition key for sending a message to a partitioned entitysetReplyTo
(String replyTo) Sets the address of an entity to send replies to.setReplyToSessionId
(String replyToSessionId) Gets or sets a session identifier augmenting theReplyTo
address.setScheduledEnqueueTime
(OffsetDateTime scheduledEnqueueTime) Sets the scheduled enqueue time of this message.setSessionId
(String sessionId) Sets the session identifier for a session-aware entity.setSubject
(String subject) Sets the subject for the message.setTimeToLive
(Duration timeToLive) Sets the duration of time before this message expires.Sets the "to" address.
-
Constructor Details
-
ServiceBusMessage
public ServiceBusMessage(byte[] body) Creates aServiceBusMessage
with given byte array body.- Parameters:
body
- The content of the Service bus message.- Throws:
NullPointerException
- ifbody
is null.
-
ServiceBusMessage
Creates aServiceBusMessage
with aUTF-8
encoded body.- Parameters:
body
- The content of the Service Bus message.- Throws:
NullPointerException
- ifbody
is null.
-
ServiceBusMessage
public ServiceBusMessage(com.azure.core.util.BinaryData body) Creates aServiceBusMessage
containing thebody
.TheBinaryData
provides various convenience API representing byte array. It also provides a way to serializeObject
intoBinaryData
.- Parameters:
body
- The data to set for thisServiceBusMessage
.- Throws:
NullPointerException
- ifbody
isnull
.- See Also:
-
BinaryData
-
ServiceBusMessage
public ServiceBusMessage(com.azure.core.amqp.models.AmqpMessageBody amqpMessageBody) This constructor provides an easy way to createServiceBusMessage
with message body as AMQP Data typesSEQUENCE
andVALUE
. In case ofSEQUENCE
, 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.- Parameters:
amqpMessageBody
- amqp message body.- Throws:
NullPointerException
- ifamqpMessageBody
isnull
.
-
ServiceBusMessage
Creates aServiceBusMessage
using properties fromreceivedMessage
. This is normally used when aServiceBusReceivedMessage
needs to be sent to another entity.- Parameters:
receivedMessage
- The received message to create new message from.- Throws:
NullPointerException
- ifreceivedMessage
isnull
.IllegalStateException
- for invalidAmqpMessageBodyType
.
-
-
Method Details
-
getApplicationProperties
Gets the set of free-formServiceBusMessage
properties which may be used for passing metadata associated with theServiceBusMessage
during Service Bus operations. A common use-case forgetApplicationProperties()
is to associate serialization hints for thegetBody()
as an aid to consumers who wish to deserialize the binary data.- Returns:
- Application properties associated with this
ServiceBusMessage
.
-
getBody
public com.azure.core.util.BinaryData getBody()Gets the actual payload wrapped by theServiceBusMessage
.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
getApplicationProperties()
when creating the event, to associate serialization hints as an aid to consumers who wish to deserialize the binary data.- Returns:
- Binary data representing the payload.
- Throws:
IllegalStateException
- if called for the messages which are not of binary data type.
-
getContentType
Gets the content type of the message.Optionally describes the payload of the message, with a descriptor following the format of RFC2045, Section 5, for example "application/json".
- Returns:
- The content type of the
ServiceBusMessage
.
-
setContentType
Sets the content type of theServiceBusMessage
.Optionally describes the payload of the message, with a descriptor following the format of RFC2045, Section 5, for example "application/json".
- Parameters:
contentType
- RFC2045 Content-Type descriptor of the message.- Returns:
- The updated
ServiceBusMessage
.
-
getCorrelationId
Gets a correlation identifier.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.
- Returns:
- The correlation id of this message.
- See Also:
-
setCorrelationId
Sets a correlation identifier.- Parameters:
correlationId
- correlation id of this message- Returns:
- The updated
ServiceBusMessage
. - See Also:
-
getSubject
Gets the subject for the message.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".
- Returns:
- The subject for the message.
-
setSubject
Sets the subject for the message.- Parameters:
subject
- The application specific subject.- Returns:
- The updated
ServiceBusMessage
object.
-
getMessageId
Gets the message id.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
.- Returns:
- Id of the
ServiceBusMessage
.
-
setMessageId
Sets the message id.- Parameters:
messageId
- The message id to be set.- Returns:
- The updated
ServiceBusMessage
. - Throws:
IllegalArgumentException
- ifmessageId
is too long.
-
getPartitionKey
Gets the partition key for sending a message to a partitioned entity.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.- Returns:
- The partition key of this message.
- See Also:
-
setPartitionKey
Sets a partition key for sending a message to a partitioned entity- Parameters:
partitionKey
- The partition key of this message.- Returns:
- The updated
ServiceBusMessage
. - Throws:
IllegalArgumentException
- ifpartitionKey
is too long or if thepartitionKey
does not match thesessionId
.- See Also:
-
getRawAmqpMessage
public com.azure.core.amqp.models.AmqpAnnotatedMessage getRawAmqpMessage()Gets theAmqpAnnotatedMessage
.- Returns:
- The raw AMQP message.
-
getReplyTo
Gets the address of an entity to send replies to.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.
- Returns:
- ReplyTo property value of this message
- See Also:
-
setReplyTo
Sets the address of an entity to send replies to.- Parameters:
replyTo
- ReplyTo property value of this message- Returns:
- The updated
ServiceBusMessage
. - See Also:
-
getTo
Gets the "to" address.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.
- Returns:
- "To" property value of this message
-
setTo
Sets the "to" address.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.
- Parameters:
to
- To property value of this message.- Returns:
- The updated
ServiceBusMessage
.
-
getTimeToLive
Gets the duration before this message expires.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
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.- Returns:
- Time to live duration of this message
- See Also:
-
setTimeToLive
Sets the duration of time before this message expires.- Parameters:
timeToLive
- Time to Live duration of this message- Returns:
- The updated
ServiceBusMessage
. - See Also:
-
getScheduledEnqueueTime
Gets the scheduled enqueue time of this message.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.
- Returns:
- the datetime at which the message will be enqueued in Azure Service Bus
- See Also:
-
setScheduledEnqueueTime
Sets the scheduled enqueue time of this message. Anull
will not be set. If this value needs to be unset it could be done by value removing fromAmqpAnnotatedMessage.getMessageAnnotations()
using keyAmqpMessageConstant.SCHEDULED_ENQUEUE_UTC_TIME_NAME
.- Parameters:
scheduledEnqueueTime
- the datetime at which this message should be enqueued in Azure Service Bus.- Returns:
- The updated
ServiceBusMessage
. - See Also:
-
getReplyToSessionId
Gets or sets a session identifier augmenting theReplyTo
address.This value augments the
reply to
information and specifies whichsessionId
should be set for the reply when sent to the reply entity.- Returns:
- The
getReplyToGroupId
property value of this message. - See Also:
-
setReplyToSessionId
Gets or sets a session identifier augmenting theReplyTo
address.- Parameters:
replyToSessionId
- The ReplyToGroupId property value of this message.- Returns:
- The updated
ServiceBusMessage
.
-
getSessionId
Gets the session identifier for a session-aware entity.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.
- Returns:
- The session id of the
ServiceBusMessage
. - See Also:
-
setSessionId
Sets the session identifier for a session-aware entity.- Parameters:
sessionId
- The session identifier to be set.- Returns:
- The updated
ServiceBusMessage
. - Throws:
IllegalArgumentException
- ifsessionId
is too long or if thesessionId
does not match thepartitionKey
.
-
addContext
Adds a new key value pair to the existing context on Message.- Parameters:
key
- The key for this context objectvalue
- The value for this context object.- Returns:
- The updated
ServiceBusMessage
. - Throws:
NullPointerException
- ifkey
orvalue
is null.
-