public final class ServiceBusReceiverClient extends Object implements AutoCloseable
ServiceBusReceivedMessage
from a specific queue or
topic on Azure Service Bus.
Create an instance of receiver
ServiceBusReceiverClient receiver = new ServiceBusClientBuilder() .connectionString( "Endpoint={eh-namespace};SharedAccessKeyName={policy-name};SharedAccessKey={key};" + "Entity-Path={hub-name}") .receiver() .queueName("<< QUEUE NAME >>") .buildClient();
Modifier and Type | Method and Description |
---|---|
void |
abandon(MessageLockToken lockToken)
Abandon a
message with its lock token. |
void |
abandon(MessageLockToken lockToken,
Map<String,Object> propertiesToModify)
Abandon a
message with its lock token and updates the message's properties. |
void |
abandon(MessageLockToken lockToken,
Map<String,Object> propertiesToModify,
String sessionId)
Abandon a
message with its lock token and updates the message's properties. |
void |
close() |
void |
complete(MessageLockToken lockToken)
Completes a
message using its lock token. |
void |
complete(MessageLockToken lockToken,
String sessionId)
Completes a
message using its lock token. |
void |
deadLetter(MessageLockToken lockToken)
Moves a
message to the deadletter sub-queue. |
void |
deadLetter(MessageLockToken lockToken,
DeadLetterOptions deadLetterOptions)
Moves a
message to the deadletter subqueue with deadletter reason, error
description, and/or modified properties. |
void |
deadLetter(MessageLockToken lockToken,
DeadLetterOptions deadLetterOptions,
String sessionId)
Moves a
message to the deadletter subqueue with deadletter reason, error
description, and/or modified properties. |
void |
deadLetter(MessageLockToken lockToken,
String sessionId)
Moves a
message to the deadletter sub-queue. |
void |
defer(MessageLockToken lockToken)
Defers a
message using its lock token. |
void |
defer(MessageLockToken lockToken,
Map<String,Object> propertiesToModify)
Defers a
message using its lock token with modified message property. |
void |
defer(MessageLockToken lockToken,
Map<String,Object> propertiesToModify,
String sessionId)
Defers a
message using its lock token with modified message property. |
void |
defer(MessageLockToken lockToken,
String sessionId)
Defers a
message using its lock token. |
String |
getEntityPath()
Gets the Service Bus resource this client interacts with.
|
String |
getFullyQualifiedNamespace()
Gets the fully qualified Service Bus namespace that the connection is associated with.
|
byte[] |
getSessionState(String sessionId)
Gets the state of a session given its identifier.
|
ServiceBusReceivedMessage |
peek()
Reads the next active message without changing the state of the receiver or the message source.
|
ServiceBusReceivedMessage |
peek(String sessionId)
Reads the next active message without changing the state of the receiver or the message source.
|
ServiceBusReceivedMessage |
peekAt(long sequenceNumber)
Starting from the given sequence number, reads next the active message without changing the state of the receiver
or the message source.
|
ServiceBusReceivedMessage |
peekAt(long sequenceNumber,
String sessionId)
Starting from the given sequence number, reads next the active message without changing the state of the receiver
or the message source.
|
com.azure.core.util.IterableStream<ServiceBusReceivedMessage> |
peekBatch(int maxMessages)
Reads the next batch of active messages without changing the state of the receiver or the message source.
|
com.azure.core.util.IterableStream<ServiceBusReceivedMessage> |
peekBatch(int maxMessages,
String sessionId)
Reads the next batch of active messages without changing the state of the receiver or the message source.
|
com.azure.core.util.IterableStream<ServiceBusReceivedMessage> |
peekBatchAt(int maxMessages,
long sequenceNumber)
Starting from the given sequence number, reads the next batch of active messages without changing the state of
the receiver or the message source.
|
com.azure.core.util.IterableStream<ServiceBusReceivedMessage> |
peekBatchAt(int maxMessages,
long sequenceNumber,
String sessionId)
Starting from the given sequence number, reads the next batch of active messages without changing the state of
the receiver or the message source.
|
com.azure.core.util.IterableStream<ServiceBusReceivedMessageContext> |
receive(int maxMessages)
Receives an iterable stream of
messages from the Service Bus entity. |
com.azure.core.util.IterableStream<ServiceBusReceivedMessageContext> |
receive(int maxMessages,
Duration maxWaitTime)
Receives an iterable stream of
messages from the Service Bus entity. |
ServiceBusReceivedMessage |
receiveDeferredMessage(long sequenceNumber)
Receives a deferred
message . |
ServiceBusReceivedMessage |
receiveDeferredMessage(long sequenceNumber,
String sessionId)
Receives a deferred
message . |
com.azure.core.util.IterableStream<ServiceBusReceivedMessage> |
receiveDeferredMessageBatch(Iterable<Long> sequenceNumbers)
Receives a batch of deferred
messages . |
com.azure.core.util.IterableStream<ServiceBusReceivedMessage> |
receiveDeferredMessageBatch(Iterable<Long> sequenceNumbers,
String sessionId)
Receives a batch of deferred
messages . |
Instant |
renewMessageLock(MessageLockToken lockToken)
Renews the lock on the specified message.
|
Instant |
renewSessionLock(String sessionId)
Sets the state of a session given its identifier.
|
void |
setSessionState(String sessionId,
byte[] sessionState)
Sets the state of a session given its identifier.
|
public String getFullyQualifiedNamespace()
{yournamespace}.servicebus.windows.net
.public String getEntityPath()
public void abandon(MessageLockToken lockToken)
message
with its lock token. This will make the message available
again for processing. Abandoning a message will increase the delivery count on the message.lockToken
- Lock token of the message.NullPointerException
- if lockToken
is null.UnsupportedOperationException
- if the receiver was opened in ReceiveMode.RECEIVE_AND_DELETE
mode.IllegalArgumentException
- if MessageLockToken.getLockToken()
returns a null lock token.public void abandon(MessageLockToken lockToken, Map<String,Object> propertiesToModify)
message
with its lock token and updates the message's properties.
This will make the message available again for processing. Abandoning a message will increase the delivery count
on the message.lockToken
- Lock token of the message.propertiesToModify
- Properties to modify on the message.NullPointerException
- if lockToken
is null.UnsupportedOperationException
- if the receiver was opened in ReceiveMode.RECEIVE_AND_DELETE
mode.IllegalArgumentException
- if MessageLockToken.getLockToken()
returns a null lock token.public void abandon(MessageLockToken lockToken, Map<String,Object> propertiesToModify, String sessionId)
message
with its lock token and updates the message's properties.
This will make the message available again for processing. Abandoning a message will increase the delivery count
on the message.lockToken
- Lock token of the message.propertiesToModify
- Properties to modify on the message.sessionId
- Session id of the message to abandon. null
if there is no session.NullPointerException
- if lockToken
is null.UnsupportedOperationException
- if the receiver was opened in ReceiveMode.RECEIVE_AND_DELETE
mode.IllegalArgumentException
- if MessageLockToken.getLockToken()
returns a null lock token.public void complete(MessageLockToken lockToken)
message
using its lock token. This will delete the message from the
service.lockToken
- Lock token of the message.NullPointerException
- if lockToken
is null.UnsupportedOperationException
- if the receiver was opened in ReceiveMode.RECEIVE_AND_DELETE
mode.IllegalArgumentException
- if MessageLockToken.getLockToken()
returns a null lock token.public void complete(MessageLockToken lockToken, String sessionId)
message
using its lock token. This will delete the message from the
service.lockToken
- Lock token of the message.sessionId
- Session id of the message to complete. null
if there is no session.NullPointerException
- if lockToken
is null.UnsupportedOperationException
- if the receiver was opened in ReceiveMode.RECEIVE_AND_DELETE
mode.IllegalArgumentException
- if MessageLockToken.getLockToken()
returns a null lock token.public void defer(MessageLockToken lockToken)
message
using its lock token. This will move message into the deferred
subqueue.lockToken
- Lock token of the message.NullPointerException
- if lockToken
is null.UnsupportedOperationException
- if the receiver was opened in ReceiveMode.RECEIVE_AND_DELETE
mode.IllegalArgumentException
- if MessageLockToken.getLockToken()
returns a null lock token.public void defer(MessageLockToken lockToken, String sessionId)
message
using its lock token. This will move message into the deferred
subqueue.lockToken
- Lock token of the message.sessionId
- Session id of the message to defer. null
if there is no session.NullPointerException
- if lockToken
is null.UnsupportedOperationException
- if the receiver was opened in ReceiveMode.RECEIVE_AND_DELETE
mode.IllegalArgumentException
- if MessageLockToken.getLockToken()
returns a null lock token.public void defer(MessageLockToken lockToken, Map<String,Object> propertiesToModify)
message
using its lock token with modified message property. This will
move message into the deferred subqueue.lockToken
- Lock token of the message.propertiesToModify
- Message properties to modify.NullPointerException
- if lockToken
is null.UnsupportedOperationException
- if the receiver was opened in ReceiveMode.RECEIVE_AND_DELETE
mode.IllegalArgumentException
- if MessageLockToken.getLockToken()
returns a null lock token.public void defer(MessageLockToken lockToken, Map<String,Object> propertiesToModify, String sessionId)
message
using its lock token with modified message property. This will
move message into the deferred subqueue.lockToken
- Lock token of the message.propertiesToModify
- Message properties to modify.sessionId
- Session id of the message to defer. null
if there is no session.NullPointerException
- if lockToken
is null.UnsupportedOperationException
- if the receiver was opened in ReceiveMode.RECEIVE_AND_DELETE
mode.IllegalArgumentException
- if MessageLockToken.getLockToken()
returns a null lock token.public void deadLetter(MessageLockToken lockToken)
message
to the deadletter sub-queue.lockToken
- Lock token of the message.NullPointerException
- if lockToken
is null.UnsupportedOperationException
- if the receiver was opened in ReceiveMode.RECEIVE_AND_DELETE
mode.IllegalArgumentException
- if MessageLockToken.getLockToken()
returns a null lock token.public void deadLetter(MessageLockToken lockToken, String sessionId)
message
to the deadletter sub-queue.lockToken
- Lock token of the message.sessionId
- Session id of the message to deadletter. null
if there is no session.NullPointerException
- if lockToken
is null.UnsupportedOperationException
- if the receiver was opened in ReceiveMode.RECEIVE_AND_DELETE
mode.IllegalArgumentException
- if MessageLockToken.getLockToken()
returns a null lock token.public void deadLetter(MessageLockToken lockToken, DeadLetterOptions deadLetterOptions)
message
to the deadletter subqueue with deadletter reason, error
description, and/or modified properties.lockToken
- Lock token of the message.deadLetterOptions
- The options to specify when moving message to the deadletter sub-queue.NullPointerException
- if lockToken
is null.UnsupportedOperationException
- if the receiver was opened in ReceiveMode.RECEIVE_AND_DELETE
mode.IllegalArgumentException
- if MessageLockToken.getLockToken()
returns a null lock token.public void deadLetter(MessageLockToken lockToken, DeadLetterOptions deadLetterOptions, String sessionId)
message
to the deadletter subqueue with deadletter reason, error
description, and/or modified properties.lockToken
- Lock token of the message.deadLetterOptions
- The options to specify when moving message to the deadletter sub-queue.sessionId
- Session id of the message to deadletter. null
if there is no session.NullPointerException
- if lockToken
is null.UnsupportedOperationException
- if the receiver was opened in ReceiveMode.RECEIVE_AND_DELETE
mode.IllegalArgumentException
- if MessageLockToken.getLockToken()
returns a null lock token.public byte[] getSessionState(String sessionId)
sessionId
- Identifier of session to get.IllegalStateException
- if the receiver is a non-session receiver.public ServiceBusReceivedMessage peek()
peek()
fetches the first active message for this receiver. Each subsequent call fetches the subsequent
message in the entity.ServiceBusReceivedMessage
.public ServiceBusReceivedMessage peek(String sessionId)
peek()
fetches the first active message for this receiver. Each subsequent call fetches the subsequent
message in the entity.sessionId
- Session id of the message to peek from. null
if there is no session.ServiceBusReceivedMessage
.public ServiceBusReceivedMessage peekAt(long sequenceNumber)
sequenceNumber
- The sequence number from where to read the message.ServiceBusReceivedMessage
.public ServiceBusReceivedMessage peekAt(long sequenceNumber, String sessionId)
sequenceNumber
- The sequence number from where to read the message.sessionId
- Session id of the message to peek from. null
if there is no session.ServiceBusReceivedMessage
.public com.azure.core.util.IterableStream<ServiceBusReceivedMessage> peekBatch(int maxMessages)
maxMessages
- The number of messages.IterableStream
of messages
that are peeked.IllegalArgumentException
- if maxMessages
is not a positive integer.public com.azure.core.util.IterableStream<ServiceBusReceivedMessage> peekBatch(int maxMessages, String sessionId)
maxMessages
- The number of messages.sessionId
- Session id of the messages to peek from. null
if there is no session.IterableStream
of messages
that are peeked.IllegalArgumentException
- if maxMessages
is not a positive integer.public com.azure.core.util.IterableStream<ServiceBusReceivedMessage> peekBatchAt(int maxMessages, long sequenceNumber)
maxMessages
- The number of messages.sequenceNumber
- The sequence number from where to start reading messages.IterableStream
of ServiceBusReceivedMessage
peeked.IllegalArgumentException
- if maxMessages
is not a positive integer.public com.azure.core.util.IterableStream<ServiceBusReceivedMessage> peekBatchAt(int maxMessages, long sequenceNumber, String sessionId)
maxMessages
- The number of messages.sequenceNumber
- The sequence number from where to start reading messages.sessionId
- Session id of the messages to peek from. null
if there is no session.IterableStream
of ServiceBusReceivedMessage
peeked.IllegalArgumentException
- if maxMessages
is not a positive integer.public com.azure.core.util.IterableStream<ServiceBusReceivedMessageContext> receive(int maxMessages)
messages
from the Service Bus entity.
The receive operation will wait for a default 1 minute for receiving a message before it times out. You can it
override by using ServiceBusReceiverClient.receive(int, Duration)
.maxMessages
- The maximum number of messages to receive.IterableStream
of at most maxMessages
messages from the Service Bus entity.IllegalArgumentException
- if maxMessages
is zero or a negative value.public com.azure.core.util.IterableStream<ServiceBusReceivedMessageContext> receive(int maxMessages, Duration maxWaitTime)
messages
from the Service Bus entity.maxMessages
- The maximum number of messages to receive.maxWaitTime
- The time the client waits for receiving a message before it times out.IterableStream
of at most maxMessages
messages from the Service Bus entity.IllegalArgumentException
- if maxMessages
or maxWaitTime
is zero or a negative value.public ServiceBusReceivedMessage receiveDeferredMessage(long sequenceNumber)
message
. Deferred messages can only be received by using
sequence number.sequenceNumber
- The sequence number
of the
message.sequenceNumber
.public ServiceBusReceivedMessage receiveDeferredMessage(long sequenceNumber, String sessionId)
message
. Deferred messages can only be received by using
sequence number.sequenceNumber
- The sequence number
of the
message.sessionId
- Session id of the deferred message.sequenceNumber
.public com.azure.core.util.IterableStream<ServiceBusReceivedMessage> receiveDeferredMessageBatch(Iterable<Long> sequenceNumbers)
messages
. Deferred messages can only be received
by using sequence number.sequenceNumbers
- The sequence numbers of the deferred messages.IterableStream
of deferred messages
.public com.azure.core.util.IterableStream<ServiceBusReceivedMessage> receiveDeferredMessageBatch(Iterable<Long> sequenceNumbers, String sessionId)
messages
. Deferred messages can only be received
by using sequence number.sequenceNumbers
- The sequence numbers of the deferred messages.sessionId
- Session id of the deferred messages. null
if there is no session.IterableStream
of deferred messages
.public Instant renewMessageLock(MessageLockToken lockToken)
ReceiveMode.PEEK_LOCK
mode, the message is locked on the server for this
receiver instance for a duration as specified during the Queue creation (LockDuration). If processing of the
message requires longer than this duration, the lock needs to be renewed. For each renewal, the lock is reset to
the entity's LockDuration value.lockToken
- Lock token of the message to renew.NullPointerException
- if lockToken
is null.UnsupportedOperationException
- if the receiver was opened in ReceiveMode.RECEIVE_AND_DELETE
mode.IllegalArgumentException
- if MessageLockToken.getLockToken()
returns a null lock token.IllegalStateException
- if the receiver is a session receiver.public Instant renewSessionLock(String sessionId)
sessionId
- Identifier of session to get.IllegalStateException
- if the receiver is a non-session receiver.public void setSessionState(String sessionId, byte[] sessionState)
sessionId
- Identifier of session to get.sessionState
- State to set on the session.IllegalStateException
- if the receiver is a non-session receiver.public void close()
close
in interface AutoCloseable
Copyright © 2020 Microsoft Corporation. All rights reserved.