pub struct AzureSessionProvider { /* private fields */ }Expand description
Azure Service Bus session provider for ordered message processing.
Implements the SessionProvider trait using the Azure Service Bus REST API,
providing exclusive session-locked access to messages within a single session.
All messages within a session are delivered in strict FIFO order.
§Session Lifecycle
- Obtain via
AzureServiceBusProvider::create_session_client. - Call
receive_messageto fetch the next message. - Process the message, then call
complete_messageorabandon_message. - Call
renew_session_lockperiodically for long-running processing to prevent session lock expiry. - Call
close_sessionwhen finished.
Implementations§
Source§impl AzureSessionProvider
impl AzureSessionProvider
Sourcepub fn new(
session_id: SessionId,
queue_name: QueueName,
session_timeout: Duration,
http_client: HttpClient,
namespace_url: String,
config: AzureServiceBusConfig,
credential: Option<Arc<dyn TokenCredential + Send + Sync>>,
) -> Self
pub fn new( session_id: SessionId, queue_name: QueueName, session_timeout: Duration, http_client: HttpClient, namespace_url: String, config: AzureServiceBusConfig, credential: Option<Arc<dyn TokenCredential + Send + Sync>>, ) -> Self
Create a new session provider.
Normally obtained through AzureServiceBusProvider::create_session_client
rather than constructed directly.
§Arguments
session_id- The session to operate on.queue_name- The queue containing the session.session_timeout- How long the session lock is expected to be held; used to computesession_expires_atand refreshed on each receive and lock renewal.http_client- Shared HTTP client (cloned from the parent provider).namespace_url- Base URL of the Service Bus namespace.config- Provider configuration (used for SAS token generation).credential- Optional token credential for AAD-based auth.
Trait Implementations§
Source§impl Debug for AzureSessionProvider
impl Debug for AzureSessionProvider
Source§impl SessionProvider for AzureSessionProvider
impl SessionProvider for AzureSessionProvider
Source§fn receive_message<'life0, 'async_trait>(
&'life0 self,
timeout: Duration,
) -> Pin<Box<dyn Future<Output = Result<Option<ReceivedMessage>, QueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn receive_message<'life0, 'async_trait>(
&'life0 self,
timeout: Duration,
) -> Pin<Box<dyn Future<Output = Result<Option<ReceivedMessage>, QueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Receive the next message from the session using PeekLock mode.
Calls DELETE {namespace}/{queue}/sessions/{sessionId}/messages/head?timeout={t}.
On success the session lock expiry is refreshed and the message lock token is
stored internally so that complete_message,
abandon_message, and
dead_letter_message can resolve the token by
receipt handle.
§Errors
QueueError::SessionNotFound– the session no longer exists or the lock expired.QueueError::ProviderError– network or broker error.
Source§fn complete_message<'life0, 'life1, 'async_trait>(
&'life0 self,
receipt: &'life1 ReceiptHandle,
) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn complete_message<'life0, 'life1, 'async_trait>(
&'life0 self,
receipt: &'life1 ReceiptHandle,
) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Complete (delete) a session message using its lock token.
Calls DELETE {namespace}/{queue}/sessions/{sessionId}/messages/{lockToken}.
§Errors
QueueError::InvalidReceipt– receipt not found locally or lock expired on broker.
Source§fn abandon_message<'life0, 'life1, 'async_trait>(
&'life0 self,
receipt: &'life1 ReceiptHandle,
) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn abandon_message<'life0, 'life1, 'async_trait>(
&'life0 self,
receipt: &'life1 ReceiptHandle,
) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Abandon a session message and make it available for re-delivery.
Calls PUT {namespace}/{queue}/sessions/{sessionId}/messages/{lockToken}.
§Errors
QueueError::InvalidReceipt– receipt not found locally or lock expired.
Source§fn dead_letter_message<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
receipt: &'life1 ReceiptHandle,
reason: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn dead_letter_message<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
receipt: &'life1 ReceiptHandle,
reason: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Dead-letter a session message.
Calls POST {namespace}/{queue}/sessions/{sessionId}/messages/{lockToken}/$deadletter
with a JSON body containing DeadLetterReason.
§Errors
QueueError::InvalidReceipt– receipt not found locally or lock expired.
Source§fn renew_session_lock<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn renew_session_lock<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Renew the session lock to extend the exclusive hold on the session.
Calls POST {namespace}/{queue}/sessions/{sessionId}/renewlock.
On success the local session_expires_at is refreshed.
§Errors
QueueError::SessionNotFound– the session lock has already expired.
Source§fn close_session<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn close_session<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<(), QueueError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Release local session state.
Clears all locally cached message lock tokens. The Azure Service Bus REST API has no endpoint to release a session lock before it expires; the broker releases the lock automatically after the session timeout configured on the queue entity (typically 30 s – 5 min). For workloads that need immediate hand-off, configure a shorter session lock duration on the queue entity or use the AMQP-based SDK which supports explicit session release.