Skip to content

Commit 36b0302

Browse files
authored
Merge pull request #106001 from jsquire/patch-3
[Service Bus] Adjust Lifetime Guidance
2 parents c0d17ea + 9ff975c commit 36b0302

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

articles/service-bus-messaging/service-bus-performance-improvements.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ For more information on minimum .NET Standard platform support, see [.NET implem
9393

9494
## Reusing factories and clients
9595
# [Azure.Messaging.ServiceBus SDK](#tab/net-standard-sdk-2)
96-
The Service Bus objects that interact with the service, such as [ServiceBusClient](/dotnet/api/azure.messaging.servicebus.servicebusclient), [ServiceBusSender](/dotnet/api/azure.messaging.servicebus.servicebussender), [ServiceBusReceiver](/dotnet/api/azure.messaging.servicebus.servicebusreceiver), and [ServiceBusProcessor](/dotnet/api/azure.messaging.servicebus.servicebusprocessor), should be registered for dependency injection as singletons (or instantiated once and shared). ServiceBusClient can be registered for dependency injection with the [ServiceBusClientBuilderExtensions](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/src/Compatibility/ServiceBusClientBuilderExtensions.cs).
96+
The Service Bus clients that interact with the service, such as [ServiceBusClient](/dotnet/api/azure.messaging.servicebus.servicebusclient), [ServiceBusSender](/dotnet/api/azure.messaging.servicebus.servicebussender), [ServiceBusReceiver](/dotnet/api/azure.messaging.servicebus.servicebusreceiver), and [ServiceBusProcessor](/dotnet/api/azure.messaging.servicebus.servicebusprocessor), should be registered for dependency injection as singletons (or instantiated once and shared). ServiceBusClient can be registered for dependency injection with the [ServiceBusClientBuilderExtensions](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/servicebus/Azure.Messaging.ServiceBus/src/Compatibility/ServiceBusClientBuilderExtensions.cs).
9797

98-
We recommend that you don't close or dispose these objects after sending or receiving each message. Closing or disposing the entity-specific objects (ServiceBusSender/Receiver/Processor) results in tearing down the link to the Service Bus service. Disposing the ServiceBusClient results in tearing down the connection to the Service Bus service.
98+
We recommend that you don't close or dispose these clients after sending or receiving each message. Closing or disposing the entity-specific objects (ServiceBusSender/Receiver/Processor) results in tearing down the link to the Service Bus service. Disposing the ServiceBusClient results in tearing down the connection to the Service Bus service.
99+
100+
This guidance does not apply to the [ServiceBusSessionReceiver](/dotnet/api/azure.messaging.servicebus.servicebussessionreceiver), as its lifetime is the same as the session itself. For applications working with the `ServiceBusSessionReceiver`, it is recommended to use a singleton instance of the `ServiceBusClient` to accept each session, which will spawn a new `ServiceBusSessionReceiver` bound to that session. Once the application finishes processing that session it should dispose the associated `ServiceBusSessionReceiver`.
99101

100102
# [Microsoft.Azure.ServiceBus SDK](#tab/net-standard-sdk)
101103

0 commit comments

Comments
 (0)