Table of Contents

Class AzureServiceBusReceiverBase<TBody, TConsumer>

Namespace
NuvTools.Notification.Messaging.Azure.ServiceBus
Assembly
NuvTools.Notification.Messaging.Azure.ServiceBus.dll

Abstract base class for Azure Service Bus receivers, containing shared message processing logic. The type of the message body to deserialize and process. The consumer type that implements IMessageConsumer<TBody> and handles the message.

public abstract class AzureServiceBusReceiverBase<TBody, TConsumer> : BackgroundService, IHostedService, IDisposable where TBody : class where TConsumer : IMessageConsumer<TBody>

Type Parameters

TBody
TConsumer
Inheritance
AzureServiceBusReceiverBase<TBody, TConsumer>
Implements
Derived
Inherited Members

Constructors

AzureServiceBusReceiverBase(ILogger, IServiceProvider, MessagingSection, TokenCredential?)

protected AzureServiceBusReceiverBase(ILogger logger, IServiceProvider serviceProvider, MessagingSection messagingSection, TokenCredential? credential = null)

Parameters

logger ILogger
serviceProvider IServiceProvider
messagingSection MessagingSection
credential TokenCredential

Properties

IsProcessing

protected abstract bool IsProcessing { get; }

Property Value

bool

Methods

DisposeProcessorAsync()

protected abstract Task DisposeProcessorAsync()

Returns

Task

ExecuteAsync(CancellationToken)

This method is called when the IHostedService starts. The implementation should return a task that represents the lifetime of the long running operation(s) being performed.

protected override Task ExecuteAsync(CancellationToken stoppingToken)

Parameters

stoppingToken CancellationToken

Triggered when StopAsync(CancellationToken) is called.

Returns

Task

A Task that represents the long running operations.

Remarks

See Worker Services in .NET for implementation guidelines.

HandleError(ProcessErrorEventArgs)

protected Task HandleError(ProcessErrorEventArgs args)

Parameters

args ProcessErrorEventArgs

Returns

Task

ProcessReceivedMessageAsync(ServiceBusReceivedMessage, string?, Func<CancellationToken, Task>, Func<CancellationToken, Task>, Func<string, string?, CancellationToken, Task>, CancellationToken)

Shared message processing logic for both regular and session receivers.

protected Task ProcessReceivedMessageAsync(ServiceBusReceivedMessage message, string? sessionId, Func<CancellationToken, Task> completeAsync, Func<CancellationToken, Task> abandonAsync, Func<string, string?, CancellationToken, Task> deadLetterAsync, CancellationToken cancellationToken)

Parameters

message ServiceBusReceivedMessage
sessionId string
completeAsync Func<CancellationToken, Task>
abandonAsync Func<CancellationToken, Task>
deadLetterAsync Func<string, string, CancellationToken, Task>
cancellationToken CancellationToken

Returns

Task

RegisterHandlers()

protected abstract void RegisterHandlers()

RestartProcessorWithRetry(CancellationToken)

protected abstract Task RestartProcessorWithRetry(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task

RestartWithRetry(Func<CancellationToken, Task>, CancellationToken)

protected Task RestartWithRetry(Func<CancellationToken, Task> startProcessingAsync, CancellationToken cancellationToken)

Parameters

startProcessingAsync Func<CancellationToken, Task>
cancellationToken CancellationToken

Returns

Task

StartProcessorAsync(CancellationToken)

protected abstract Task StartProcessorAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task

StopAsync(CancellationToken)

Triggered when the application host is performing a graceful shutdown.

public override Task StopAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Indicates that the shutdown process should no longer be graceful.

Returns

Task

A Task that represents the asynchronous Stop operation.

StopProcessorAsync(CancellationToken)

protected abstract Task StopProcessorAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

Task