Table of Contents

Class AzureServiceBusSender<TBody>

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

Provides a base implementation for sending messages to Azure Service Bus entities (queues or topics).

public abstract class AzureServiceBusSender<TBody> : IMessageSender<TBody> where TBody : class

Type Parameters

TBody

The type of the message body. Must be a reference type.

Inheritance
AzureServiceBusSender<TBody>
Implements
Inherited Members

Remarks

This abstract class encapsulates the logic for serializing messages and sending them to Azure Service Bus. It supports initialization using a ServiceBusClient, a connection string, or a MessagingSection configuration (which may authenticate by connection string or by Entra ID credential).

Constructors

AzureServiceBusSender(ServiceBusClient, string)

Initializes a new instance of the AzureServiceBusSender<TBody> class using an existing ServiceBusClient.

protected AzureServiceBusSender(ServiceBusClient client, string entityName)

Parameters

client ServiceBusClient

The Azure Service Bus client.

entityName string

The name of the queue or topic to send messages to.

Exceptions

ArgumentNullException

Thrown if client is null.

ArgumentException

Thrown if entityName is null or empty.

AzureServiceBusSender(MessagingSection, TokenCredential?)

Initializes a new instance of the AzureServiceBusSender<TBody> class using a MessagingSection configuration.

protected AzureServiceBusSender(MessagingSection messagingSection, TokenCredential? credential = null)

Parameters

messagingSection MessagingSection

The messaging configuration section containing connection details.

credential TokenCredential

Credential used when the section authenticates by fully qualified namespace. When null, one is derived from ManagedIdentityClientId.

AzureServiceBusSender(string, string)

Initializes a new instance of the AzureServiceBusSender<TBody> class using a connection string.

protected AzureServiceBusSender(string connectionString, string entityName)

Parameters

connectionString string

The Azure Service Bus connection string.

entityName string

The name of the queue or topic to send messages to.

Methods

SendAsync(Message<TBody>, CancellationToken)

Sends a message asynchronously to the configured Azure Service Bus entity.

public Task SendAsync(Message<TBody> message, CancellationToken cancellationToken = default)

Parameters

message Message<TBody>

The message to send, including body and metadata.

cancellationToken CancellationToken

A token to observe while waiting for the task to complete.

Returns

Task

A task representing the asynchronous send operation.

Exceptions

ArgumentNullException

Thrown if message is null.