다음을 통해 공유


ServiceBusSessionProcessor Class

Definition

The ServiceBusSessionProcessor provides an abstraction around a set of ServiceBusSessionReceiver that allows using an event based model for processing received ServiceBusReceivedMessage. It is constructed by calling CreateSessionProcessor(String, ServiceBusSessionProcessorOptions). The message handler is specified with the ProcessMessageAsync property. The error handler is specified with the ProcessErrorAsync property. To start processing after the handlers have been specified, call StartProcessingAsync(CancellationToken).

public class ServiceBusSessionProcessor : IAsyncDisposable
type ServiceBusSessionProcessor = class
    interface IAsyncDisposable
Public Class ServiceBusSessionProcessor
Implements IAsyncDisposable
Inheritance
ServiceBusSessionProcessor
Implements

Remarks

The ServiceBusSessionProcessor is safe to cache and use for the lifetime of an application or until the ServiceBusClient that it was created by is disposed. Caching the processor is recommended when the application is processing messages regularly. The sender is responsible for ensuring efficient network, CPU, and memory use. Calling DisposeAsync() on the associated ServiceBusClient as the application is shutting down will ensure that network resources and other unmanaged objects used by the processor are properly cleaned up.

Constructors

ServiceBusSessionProcessor()

Initializes a new instance of the ServiceBusSessionProcessor class for mocking.

ServiceBusSessionProcessor(ServiceBusClient, String, ServiceBusSessionProcessorOptions)

Initializes a new instance of the ServiceBusSessionProcessor class for use with derived types.

ServiceBusSessionProcessor(ServiceBusClient, String, String, ServiceBusSessionProcessorOptions)

Initializes a new instance of the ServiceBusSessionProcessor class for use with derived types.

Properties

AutoCompleteMessages

Gets a value that indicates whether the processor should automatically complete messages after the message handler has completed processing. If the message handler triggers an exception, the message will not be automatically completed.

EntityPath

Gets the path of the Service Bus entity that the processor is connected to, specific to the Service Bus namespace that contains it.

FullyQualifiedNamespace

Gets the fully qualified Service Bus namespace that the receiver is associated with. This is likely to be similar to {yournamespace}.servicebus.windows.net.

Identifier

Gets the Identifier used to identify this processor client. If null or empty, a random unique value will be will be used.

InnerProcessor

The ServiceBusProcessor that the session processor delegates to. This can be overriden for testing purposes.

IsClosed

Indicates whether or not this ServiceBusSessionProcessor has been closed.

IsProcessing

Gets whether or not this processor is currently processing messages.

MaxAutoLockRenewalDuration

Gets the maximum duration within which the session lock will be renewed automatically.

MaxConcurrentCallsPerSession

Gets the maximum number of calls to the callback the processor will initiate per session. Thus the total number of callbacks will be equal to MaxConcurrentSessions * MaxConcurrentCallsPerSession. The default value is 1.

MaxConcurrentSessions

Gets the maximum number of sessions that will be processed concurrently by the processor. The default value is 8.

PrefetchCount

Gets the number of messages that will be eagerly requested from Queues or Subscriptions during processing. This is intended to help maximize throughput by allowing the processor to receive from a local cache rather than waiting on a service request.

ReceiveMode

Gets the ReceiveMode used to specify how messages are received. Defaults to PeekLock mode.

SessionIdleTimeout

Gets the maximum amount of time to wait for a message to be received for the currently active session. After this time has elapsed, the processor will close the session and attempt to process another session. If not specified, the TryTimeout will be used.

Methods

CloseAsync(CancellationToken)

Performs the task needed to clean up resources used by the ServiceBusSessionProcessor.

DisposeAsync()

Performs the task needed to clean up resources used by the ServiceBusSessionProcessor. This is equivalent to calling CloseAsync(CancellationToken).

OnProcessErrorAsync(ProcessErrorEventArgs)

Invokes the error event handler when an error has occurred during processing. This method can be overridden to raise an event manually for testing purposes.

OnProcessSessionMessageAsync(ProcessSessionMessageEventArgs)

Invokes the process message event handler after a message has been received. This method can be overriden to raise an event manually for testing purposes.

OnSessionClosingAsync(ProcessSessionEventArgs)

Invokes the session close event handler when a session is about to be closed for processing. This method can be overriden to raise an event manually for testing purposes.

OnSessionInitializingAsync(ProcessSessionEventArgs)

Invokes the session open event handler when a new session is about to be processed. This method can be overriden to raise an event manually for testing purposes.

StartProcessingAsync(CancellationToken)

Signals the processor to begin processing messages. Should this method be called while the processor is already running, an InvalidOperationException is thrown.

StopProcessingAsync(CancellationToken)

Signals the processor to stop processing messaging. Should this method be called while the processor is not running, no action is taken. This method will not close the underlying receivers, but will cause the receivers to stop receiving. Any in-flight message handlers will be awaited, and this method will not return until all in-flight message handlers have returned. To close the underlying receivers, CloseAsync(CancellationToken) should be called. If CloseAsync(CancellationToken) is called, the processor cannot be restarted. If you wish to resume processing at some point after calling this method, you can call StartProcessingAsync(CancellationToken).

UpdateConcurrency(Int32, Int32)

Updates the concurrency for the processor. This method can be used to dynamically change the concurrency of a running processor.

UpdatePrefetchCount(Int32)

Updates the prefetch count for the processor. This method can be used to dynamically change the prefetch count of a running processor.

Events

ProcessErrorAsync

The handler responsible for processing unhandled exceptions thrown while this processor is running. Implementation is mandatory.

ProcessMessageAsync

The handler responsible for processing messages received from the Queue or Subscription. Implementation is mandatory.

SessionClosingAsync

Optional handler that can be set to be notified when a session is about to be closed for processing. This means that the most recent ReceiveMessageAsync(Nullable<TimeSpan>, CancellationToken) call timed out, or that ReleaseSession() was called in the ProcessMessageAsync handler.

SessionInitializingAsync

Optional handler that can be set to be notified when a new session is about to be processed.

Applies to