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
TBodyThe type of the message body. Must be a reference type.
- Inheritance
-
AzureServiceBusSender<TBody>
- Implements
-
IMessageSender<TBody>
- 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
clientServiceBusClientThe Azure Service Bus client.
entityNamestringThe name of the queue or topic to send messages to.
Exceptions
- ArgumentNullException
Thrown if
clientis null.- ArgumentException
Thrown if
entityNameis 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
messagingSectionMessagingSectionThe messaging configuration section containing connection details.
credentialTokenCredentialCredential 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
connectionStringstringThe Azure Service Bus connection string.
entityNamestringThe 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
messageMessage<TBody>The message to send, including body and metadata.
cancellationTokenCancellationTokenA token to observe while waiting for the task to complete.
Returns
- Task
A task representing the asynchronous send operation.
Exceptions
- ArgumentNullException
Thrown if
messageis null.