-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix object disposed exception during channel Recovery (#1648)
* Fix object disposed exception during channel Recovery Fixes #1647 * * Remove channels that do not recover successfully * * Hold the `_channelsSemaphore` for a shorter period of time.
- Loading branch information
1 parent
db5bc23
commit 5aca35a
Showing
5 changed files
with
109 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>GH_1647</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../../../RabbitMQ.Client\RabbitMQ.Client.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,29 @@ | ||
#pragma warning disable CA2007 // Consider calling ConfigureAwait on the awaited task | ||
using System.Text; | ||
using RabbitMQ.Client; | ||
|
||
ConnectionFactory connectionFactory = new() | ||
{ | ||
AutomaticRecoveryEnabled = true, | ||
UserName = "guest", | ||
Password = "guest" | ||
}; | ||
|
||
var props = new BasicProperties(); | ||
byte[] msg = Encoding.UTF8.GetBytes("test"); | ||
using var connection = await connectionFactory.CreateConnectionAsync(); | ||
for (int i = 0; i < 300; i++) | ||
{ | ||
try | ||
{ | ||
using var channel = await connection.CreateChannelAsync(); // New channel for each message | ||
await Task.Delay(1000); | ||
await channel.BasicPublishAsync(string.Empty, string.Empty, props, msg); | ||
Console.WriteLine($"Sent message {i}"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine($"Failed to send message {i}: {ex.Message}"); | ||
await Task.Delay(1000); | ||
} | ||
} |