public final class ServiceBusSessionReceiverClient extends Object implements AutoCloseable
ServiceBusReceiverClient
instances that are tied to the locked sessions.
Receive messages from a specific session
Use ServiceBusSessionReceiverClient.acceptSession(String)
to acquire the lock of a session if you know the session id.
// The connectionString/sessionQueueName must be set by the application. The 'connectionString' format is shown below. // "Endpoint={fully-qualified-namespace};SharedAccessKeyName={policy-name};SharedAccessKey={key}" ServiceBusSessionReceiverClient sessionReceiver = new ServiceBusClientBuilder() .connectionString(connectionString) .sessionReceiver() .queueName(sessionQueueName) .buildClient(); ServiceBusReceiverClient receiver = sessionReceiver.acceptSession("<< my-session-id >>"); // Use the receiver and finally close it along with the sessionReceiver. receiver.close(); sessionReceiver.close();
Receive messages from the first available session
Use ServiceBusSessionReceiverClient.acceptNextSession()
to acquire the lock of the next available session without specifying the session
id.
// The connectionString/sessionQueueName must be set by the application. The 'connectionString' format is shown below. // "Endpoint={fully-qualified-namespace};SharedAccessKeyName={policy-name};SharedAccessKey={key}" ServiceBusSessionReceiverClient sessionReceiver = new ServiceBusClientBuilder() .connectionString( "Endpoint={fully-qualified-namespace};SharedAccessKeyName={policy-name};SharedAccessKey={key}") .sessionReceiver() .queueName("<< QUEUE NAME >>") .buildClient(); ServiceBusReceiverClient receiver = sessionReceiver.acceptNextSession(); // Use the receiver and finally close it along with the sessionReceiver. receiver.close(); sessionReceiver.close();
Modifier and Type | Method and Description |
---|---|
ServiceBusReceiverClient |
acceptNextSession()
Acquires a session lock for the next available session and creates a
ServiceBusReceiverClient
to receive messages from the session. |
ServiceBusReceiverClient |
acceptSession(String sessionId)
Acquires a session lock for
sessionId and create a ServiceBusReceiverClient
to receive messages from the session. |
void |
close() |
public ServiceBusReceiverClient acceptNextSession()
ServiceBusReceiverClient
to receive messages from the session. It will wait until a session is available if no one is available
immediately.ServiceBusReceiverClient
that is tied to the available session.UnsupportedOperationException
- if the queue or topic subscription is not session-enabled.AmqpException
- if the operation times out. The timeout duration is the tryTimeout
of when you build this client with the ServiceBusClientBuilder.retryOptions(AmqpRetryOptions)
.public ServiceBusReceiverClient acceptSession(String sessionId)
sessionId
and create a ServiceBusReceiverClient
to receive messages from the session. If the session is already locked by another client, an
AmqpException
is thrown immediately.sessionId
- The session id.ServiceBusReceiverClient
that is tied to the specified session.NullPointerException
- if sessionId
is null.IllegalArgumentException
- if sessionId
is empty.UnsupportedOperationException
- if the queue or topic subscription is not session-enabled.ServiceBusException
- if the lock cannot be acquired.AmqpException
- if the operation times out. The timeout duration is the tryTimeout
of when you build this client with the ServiceBusClientBuilder.retryOptions(AmqpRetryOptions)
.public void close()
close
in interface AutoCloseable
Copyright © 2021 Microsoft Corporation. All rights reserved.