ServiceBusProcessor Class

Definition

The ServiceBusProcessor provides an abstraction around a set of ServiceBusReceiver that allows using an event based model for processing received ServiceBusReceivedMessage. It is constructed by calling CreateProcessor(String, ServiceBusProcessorOptions). 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 ServiceBusProcessor : IAsyncDisposable
type ServiceBusProcessor = class
    interface IAsyncDisposable
Public Class ServiceBusProcessor
Implements IAsyncDisposable
Inheritance
ServiceBusProcessor
Implements

Constructors

ServiceBusProcessor()

Initializes a new instance of the ServiceBusProcessor class for mocking.

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.

IsClosed

Indicates whether or not this ServiceBusProcessor has been closed.

IsProcessing

Gets whether or not this processor is currently processing messages.

MaxAutoLockRenewalDuration

Gets the maximum duration within which the lock will be renewed automatically. This value should be greater than the longest message lock duration; for example, the LockDuration Property.

MaxConcurrentCalls

Gets the maximum number of concurrent calls to the ProcessMessageAsync message handler the processor should initiate.

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.

Methods

CloseAsync(CancellationToken)

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

DisposeAsync()

Performs the task needed to clean up resources used by the ServiceBusProcessor. This is equivalent to calling CloseAsync(CancellationToken) with the default Azure.Messaging.ServiceBus.LinkCloseMode.

OnProcessErrorAsync(ProcessErrorEventArgs)

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

OnProcessMessageAsync(ProcessMessageEventArgs)

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.

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. To close the underlying receivers, CloseAsync(CancellationToken) should be called.

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.

Applies to