Getting Started
Architecture
NServiceBus
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Samples

Configuration

This page targets a pre-release version. Pre-releases are subject to change and samples are not guaranteed to be fully functional.

Configuring an endpoint

To use Azure Service Bus as the underlying transport:

var transport = new AzureServiceBusTransport("Endpoint=sb://[NAMESPACE].servicebus.windows.net/;SharedAccessKeyName=[KEYNAME];SharedAccessKey=[KEY]", TopicTopology.Default);
endpointConfiguration.UseTransport(transport);

Connectivity

These settings control how the transport connects to the broker.

Transport

  • UseWebSockets: Configures the transport to use AMQP over websockets.
  • WebProxy: Configures an optional web-proxy to use with AMQP over websockets.
  • TimeToWaitBeforeTriggeringCircuitBreaker: The time to wait before triggering the circuit breaker after a critical error occurred. Defaults to 2 minutes.

Retry-policy

  • CustomRetryPolicy(RetryPolicy): Allows replacement of the default retry policy.

Token-credentials

Enables usage of Microsoft Entra ID authentication such as managed identities for Azure resources instead of the shared secret in the connection string.

var transportWithTokenCredentials = new AzureServiceBusTransport("[NAMESPACE].servicebus.windows.net", new DefaultAzureCredential(), TopicTopology.Default);
endpointConfiguration.UseTransport(transportWithTokenCredentials);

Entity creation

These settings control how the transport creates entities in the Azure Service Bus namespace.

Access rights

The transport can be run without Manage rights when using a shared access policy or without the Azure Service Bus Data Owner role if authenticating using Managed Identities.

To run without manage rights:

Topology

Settings

Controlling the prefetch count

When consuming messages from the broker, throughput can be improved by having the consumer prefetch additional messages. The prefetch count is calculated by multiplying maximum concurrency by the prefetch multiplier. The default value of the multiplier is 10, but it can be changed by using the following:

transport.PrefetchMultiplier = 3;

Alternatively, the whole calculation can be overridden by setting the prefetch count directly using the following:

transport.PrefetchCount = 100;

To disable prefetching, prefetch count should be set to zero.

Lock-renewal

For all supported transport transaction modes (except TransportTransactionMode.None), the transport utilizes a peek-lock mechanism to ensure that only one instance of an endpoint can process a message. The default lock duration is set during entity creation. By default, the transport uses the SDK's default maximum auto lock renewal duration of 5 minutes.

To ensure smooth processing, it is recommended to configuring the MaxAutoLockRenewalDuration property to be greater than the longest running handler for the endpoint. This helps avoid LockLostException and ensures the message is properly handled by the recoverability process.

The lock can be auto-renewed beyond the default by overriding the MaxAutoLockRenewalDuration.

transport.MaxAutoLockRenewalDuration = TimeSpan.FromMinutes(10);