ServiceBusMessage Class
- java.
lang. Object - com.
azure. messaging. servicebus. ServiceBusMessage
- com.
public class ServiceBusMessage
The data structure encapsulating the message being sent to Service Bus. The message structure is discussed in detail in the product documentation.
Constructor Summary
Constructor | Description |
---|---|
ServiceBusMessage(byte[] body) |
Creates a ServiceBusMessage with given byte array body. |
ServiceBusMessage(AmqpMessageBody amqpMessageBody) |
This constructor provides an easy way to create ServiceBusMessage with message body as AMQP Data types |
ServiceBusMessage(BinaryData body) |
Creates a ServiceBusMessage containing the |
ServiceBusMessage(ServiceBusReceivedMessage receivedMessage) |
Creates a ServiceBusMessage using properties from |
ServiceBusMessage(String body) |
Creates a ServiceBusMessage with a UTF-8 encoded body. |
Method Summary
Modifier and Type | Method and Description |
---|---|
Service |
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. |
Binary |
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. |
Amqp |
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 getReplyTo() address. |
Offset |
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. |
Service |
setContentType(String contentType)
Sets the content type of the ServiceBusMessage. |
Service |
setCorrelationId(String correlationId)
Sets a correlation identifier. |
Service |
setMessageId(String messageId)
Sets the message id. |
Service |
setPartitionKey(String partitionKey)
Sets a partition key for sending a message to a partitioned entity |
Service |
setReplyTo(String replyTo)
Sets the address of an entity to send replies to. |
Service |
setReplyToSessionId(String replyToSessionId)
Gets or sets a session identifier augmenting the getReplyTo() address. |
Service |
setScheduledEnqueueTime(OffsetDateTime scheduledEnqueueTime)
Sets the scheduled enqueue time of this message. |
Service |
setSessionId(String sessionId)
Sets the session identifier for a session-aware entity. |
Service |
setSubject(String subject)
Sets the subject for the message. |
Service |
setTimeToLive(Duration timeToLive)
Sets the duration of time before this message expires. |
Service |
setTo(String to)
Sets the "to" address. |
Methods inherited from java.lang.Object
Constructor Details
ServiceBusMessage
public ServiceBusMessage(byte[] body)
Creates a ServiceBusMessage with given byte array body.
Parameters:
ServiceBusMessage
public ServiceBusMessage(AmqpMessageBody amqpMessageBody)
This constructor provides an easy way to create 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.
Parameters:
ServiceBusMessage
public ServiceBusMessage(BinaryData body)
Creates a ServiceBusMessage containing the body
.The BinaryData provides various convenience API representing byte array. It also provides a way to serialize Object into BinaryData.
Parameters:
ServiceBusMessage
public ServiceBusMessage(ServiceBusReceivedMessage receivedMessage)
Creates a ServiceBusMessage using properties from receivedMessage
. This is normally used when a ServiceBusReceivedMessage needs to be sent to another entity.
Parameters:
ServiceBusMessage
public ServiceBusMessage(String body)
Creates a ServiceBusMessage with a UTF-8 encoded body.
Parameters:
Method Details
addContext
public ServiceBusMessage addContext(String key, Object value)
Adds a new key value pair to the existing context on Message.
Parameters:
Returns:
getApplicationProperties
public Map
Gets the set of free-form 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 getBody() as an aid to consumers who wish to deserialize the binary data.
Returns:
getBody
public BinaryData getBody()
Gets the actual payload wrapped by the 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 getApplicationProperties() when creating the event, to associate serialization hints as an aid to consumers who wish to deserialize the binary data.
Returns:
getContentType
public String 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:
getCorrelationId
public String 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:
getMessageId
public String 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:
getPartitionKey
public String 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 getSessionId() property overrides this value.
Returns:
getRawAmqpMessage
public AmqpAnnotatedMessage getRawAmqpMessage()
Gets the AmqpAnnotatedMessage.
Returns:
getReplyTo
public String 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:
getReplyToSessionId
public String getReplyToSessionId()
Gets or sets a session identifier augmenting the getReplyTo() address.
This value augments the getReplyTo() information and specifies which sessionId
should be set for the reply when sent to the reply entity.
Returns:
getReplyToGroupId
property value of this message.getScheduledEnqueueTime
public OffsetDateTime 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:
getSessionId
public String 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:
getSubject
public String 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:
getTimeToLive
public Duration 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:
getTo
public String 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:
setContentType
public ServiceBusMessage setContentType(String contentType)
Sets the content type of the ServiceBusMessage.
Optionally describes the payload of the message, with a descriptor following the format of RFC2045, Section 5, for example "application/json".
Parameters:
Returns:
setCorrelationId
public ServiceBusMessage setCorrelationId(String correlationId)
Sets a correlation identifier.
Parameters:
Returns:
setMessageId
public ServiceBusMessage setMessageId(String messageId)
Sets the message id.
Parameters:
Returns:
setPartitionKey
public ServiceBusMessage setPartitionKey(String partitionKey)
Sets a partition key for sending a message to a partitioned entity
Parameters:
Returns:
setReplyTo
public ServiceBusMessage setReplyTo(String replyTo)
Sets the address of an entity to send replies to.
Parameters:
Returns:
setReplyToSessionId
public ServiceBusMessage setReplyToSessionId(String replyToSessionId)
Gets or sets a session identifier augmenting the getReplyTo() address.
Parameters:
Returns:
setScheduledEnqueueTime
public ServiceBusMessage setScheduledEnqueueTime(OffsetDateTime scheduledEnqueueTime)
Sets the scheduled enqueue time of this message. A 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.
Parameters:
Returns:
setSessionId
public ServiceBusMessage setSessionId(String sessionId)
Sets the session identifier for a session-aware entity.
Parameters:
Returns:
setSubject
public ServiceBusMessage setSubject(String subject)
Sets the subject for the message.
Parameters:
Returns:
setTimeToLive
public ServiceBusMessage setTimeToLive(Duration timeToLive)
Sets the duration of time before this message expires.
Parameters:
Returns:
setTo
public ServiceBusMessage setTo(String to)
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:
Returns: