38
38
using System . Threading . Tasks ;
39
39
using RabbitMQ . Client ;
40
40
41
+ const ushort MAX_OUTSTANDING_CONFIRMS = 256 ;
42
+
41
43
const int MESSAGE_COUNT = 50_000 ;
42
44
bool debug = false ;
43
45
46
+ var channelOpts = new CreateChannelOptions
47
+ {
48
+ PublisherConfirmationsEnabled = true ,
49
+ PublisherConfirmationTrackingEnabled = true ,
50
+ MaxOutstandingPublisherConfirmations = MAX_OUTSTANDING_CONFIRMS
51
+ } ;
52
+
44
53
#pragma warning disable CS8321 // Local function is declared but never used
45
54
46
55
await PublishMessagesIndividuallyAsync ( ) ;
@@ -53,12 +62,12 @@ static Task<IConnection> CreateConnectionAsync()
53
62
return factory . CreateConnectionAsync ( ) ;
54
63
}
55
64
56
- static async Task PublishMessagesIndividuallyAsync ( )
65
+ async Task PublishMessagesIndividuallyAsync ( )
57
66
{
58
67
Console . WriteLine ( $ "{ DateTime . Now } [INFO] publishing { MESSAGE_COUNT : N0} messages and handling confirms per-message") ;
59
68
60
69
await using IConnection connection = await CreateConnectionAsync ( ) ;
61
- await using IChannel channel = await connection . CreateChannelAsync ( new CreateChannelOptions { PublisherConfirmationsEnabled = true , PublisherConfirmationTrackingEnabled = true } ) ;
70
+ await using IChannel channel = await connection . CreateChannelAsync ( channelOpts ) ;
62
71
63
72
// declare a server-named queue
64
73
QueueDeclareOk queueDeclareResult = await channel . QueueDeclareAsync ( ) ;
@@ -85,18 +94,18 @@ static async Task PublishMessagesIndividuallyAsync()
85
94
Console . WriteLine ( $ "{ DateTime . Now } [INFO] published { MESSAGE_COUNT : N0} messages individually in { sw . ElapsedMilliseconds : N0} ms") ;
86
95
}
87
96
88
- static async Task PublishMessagesInBatchAsync ( )
97
+ async Task PublishMessagesInBatchAsync ( )
89
98
{
90
99
Console . WriteLine ( $ "{ DateTime . Now } [INFO] publishing { MESSAGE_COUNT : N0} messages and handling confirms in batches") ;
91
100
92
101
await using IConnection connection = await CreateConnectionAsync ( ) ;
93
- await using IChannel channel = await connection . CreateChannelAsync ( new CreateChannelOptions { PublisherConfirmationsEnabled = true , PublisherConfirmationTrackingEnabled = true } ) ;
102
+ await using IChannel channel = await connection . CreateChannelAsync ( channelOpts ) ;
94
103
95
104
// declare a server-named queue
96
105
QueueDeclareOk queueDeclareResult = await channel . QueueDeclareAsync ( ) ;
97
106
string queueName = queueDeclareResult . QueueName ;
98
107
99
- int batchSize = 1000 ;
108
+ int batchSize = MAX_OUTSTANDING_CONFIRMS ;
100
109
int outstandingMessageCount = 0 ;
101
110
102
111
var sw = new Stopwatch ( ) ;
@@ -154,12 +163,8 @@ async Task HandlePublishConfirmsAsynchronously()
154
163
155
164
await using IConnection connection = await CreateConnectionAsync ( ) ;
156
165
157
- var channelOptions = new CreateChannelOptions
158
- {
159
- PublisherConfirmationsEnabled = true ,
160
- PublisherConfirmationTrackingEnabled = false
161
- } ;
162
- await using IChannel channel = await connection . CreateChannelAsync ( channelOptions ) ;
166
+ channelOpts . PublisherConfirmationTrackingEnabled = false ;
167
+ await using IChannel channel = await connection . CreateChannelAsync ( channelOpts ) ;
163
168
164
169
// declare a server-named queue
165
170
QueueDeclareOk queueDeclareResult = await channel . QueueDeclareAsync ( ) ;
0 commit comments