-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dispose clients on host shutdown rather than listener dispose (#39225)
* Dispose clients on host shutdown rather than listener dispose * Remove project reference * Update version - for some reason the auto-update job failed
- Loading branch information
1 parent
c86f34f
commit 61c04a1
Showing
7 changed files
with
75 additions
and
28 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
sdk/servicebus/Microsoft.Azure.WebJobs.Extensions.ServiceBus/CHANGELOG.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...icrosoft.Azure.WebJobs.Extensions.ServiceBus/src/Primitives/CachedClientCleanupService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Microsoft.Azure.WebJobs.ServiceBus | ||
{ | ||
internal class CachedClientCleanupService : IHostedService | ||
{ | ||
private readonly MessagingProvider _provider; | ||
|
||
public CachedClientCleanupService(MessagingProvider provider) | ||
{ | ||
_provider = provider; | ||
} | ||
|
||
public Task StartAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
public async Task StopAsync(CancellationToken cancellationToken) | ||
{ | ||
foreach (var receiver in _provider.MessageReceiverCache.Values) | ||
{ | ||
await receiver.DisposeAsync().ConfigureAwait(false); | ||
} | ||
_provider.MessageReceiverCache.Clear(); | ||
|
||
foreach (var sender in _provider.MessageSenderCache.Values) | ||
{ | ||
await sender.DisposeAsync().ConfigureAwait(false); | ||
} | ||
_provider.MessageSenderCache.Clear(); | ||
|
||
foreach (var client in _provider.ClientCache.Values) | ||
{ | ||
await client.DisposeAsync().ConfigureAwait(false); | ||
} | ||
_provider.ClientCache.Clear(); | ||
_provider.ActionsCache.Clear(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters