Path: redb-route/redb.Route.AzureServiceBus/AzureServiceBusConnectionFactory.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.AzureServiceBus/AzureServiceBusConnectionFactory.cs
----
using Azure.Messaging.ServiceBus;
using redb.Route.Core;
namespace redb.Route.AzureServiceBus;
///
/// POCO factory for creating instances.
/// Register in the route context registry for shared client configuration:
/// context.AddToRegistry("myAsb", new AzureServiceBusConnectionFactory { ... });
/// Reference from URI: asb://queue?connectionFactory=myAsb
///
public sealed class AzureServiceBusConnectionFactory
{
/// Azure Service Bus connection string.
[Sensitive]
public string ConnectionString { get; set; } = "";
/// Maximum number of retries (default 3).
public int MaxRetries { get; set; } = 3;
/// Initial retry delay in milliseconds (default 800).
public int DelayMs { get; set; } = 800;
/// Maximum retry delay in milliseconds (default 60000).
public int MaxDelayMs { get; set; } = 60_000;
/// Retry mode: Exponential or Fixed (default Exponential).
public ServiceBusRetryMode RetryMode { get; set; } = ServiceBusRetryMode.Exponential;
/// Per-try timeout in milliseconds (default 60000).
public int TryTimeoutMs { get; set; } = 60_000;
/// Transport type: AmqpTcp or AmqpWebSockets (default AmqpTcp).
public ServiceBusTransportType TransportType { get; set; } = ServiceBusTransportType.AmqpTcp;
/// Web proxy address. Forces AmqpWebSockets transport when set.
public string? ProxyAddress { get; set; }
/// Builds a configured .
public ServiceBusClient Build()
{
var options = new ServiceBusClientOptions
{
TransportType = TransportType,
RetryOptions = new ServiceBusRetryOptions
{
Mode = RetryMode,
MaxRetries = MaxRetries,
Delay = TimeSpan.FromMilliseconds(DelayMs),
MaxDelay = TimeSpan.FromMilliseconds(MaxDelayMs),
TryTimeout = TimeSpan.FromMilliseconds(TryTimeoutMs)
}
};
if (!string.IsNullOrWhiteSpace(ProxyAddress))
{
options.TransportType = ServiceBusTransportType.AmqpWebSockets;
options.WebProxy = new System.Net.WebProxy(ProxyAddress);
}
return new ServiceBusClient(ConnectionString, options);
}
}