Skip to content

Commit 6e39df0

Browse files
committed
Require IChannel for AsyncDefaultBasicConsumer
1 parent d444230 commit 6e39df0

File tree

5 files changed

+15
-23
lines changed

5 files changed

+15
-23
lines changed

projects/Benchmarks/Networking/Networking_BasicDeliver_Commons.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static async Task Publish_Hello_World(IConnection connection, uint messag
1414
using (IChannel channel = await connection.CreateChannelAsync())
1515
{
1616
QueueDeclareOk queue = await channel.QueueDeclareAsync();
17-
var consumer = new CountingConsumer(messageCount);
17+
var consumer = new CountingConsumer(channel, messageCount);
1818
await channel.BasicConsumeAsync(queue.QueueName, true, consumer);
1919

2020
for (int i = 0; i < messageCount; i++)
@@ -35,7 +35,7 @@ internal sealed class CountingConsumer : AsyncDefaultBasicConsumer
3535

3636
public Task CompletedTask => _tcs.Task;
3737

38-
public CountingConsumer(uint messageCount)
38+
public CountingConsumer(IChannel channel, uint messageCount) : base(channel)
3939
{
4040
_remainingCount = (int)messageCount;
4141
_tcs = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);

projects/RabbitMQ.Client/PublicAPI.Shipped.txt

-4
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,11 @@ RabbitMQ.Client.AmqpTimestamp.AmqpTimestamp() -> void
9696
RabbitMQ.Client.AmqpTimestamp.AmqpTimestamp(long unixTime) -> void
9797
RabbitMQ.Client.AmqpTimestamp.Equals(RabbitMQ.Client.AmqpTimestamp other) -> bool
9898
RabbitMQ.Client.AsyncDefaultBasicConsumer
99-
RabbitMQ.Client.AsyncDefaultBasicConsumer.AsyncDefaultBasicConsumer() -> void
10099
RabbitMQ.Client.AsyncDefaultBasicConsumer.AsyncDefaultBasicConsumer(RabbitMQ.Client.IChannel channel) -> void
101100
RabbitMQ.Client.AsyncDefaultBasicConsumer.Channel.get -> RabbitMQ.Client.IChannel
102-
RabbitMQ.Client.AsyncDefaultBasicConsumer.Channel.set -> void
103101
RabbitMQ.Client.AsyncDefaultBasicConsumer.ConsumerTags.get -> string[]
104102
RabbitMQ.Client.AsyncDefaultBasicConsumer.IsRunning.get -> bool
105-
RabbitMQ.Client.AsyncDefaultBasicConsumer.IsRunning.set -> void
106103
RabbitMQ.Client.AsyncDefaultBasicConsumer.ShutdownReason.get -> RabbitMQ.Client.ShutdownEventArgs
107-
RabbitMQ.Client.AsyncDefaultBasicConsumer.ShutdownReason.set -> void
108104
RabbitMQ.Client.BasicGetResult
109105
RabbitMQ.Client.BasicGetResult.BasicGetResult(ulong deliveryTag, bool redelivered, string exchange, string routingKey, uint messageCount, RabbitMQ.Client.IReadOnlyBasicProperties basicProperties, System.ReadOnlyMemory<byte> body) -> void
110106
RabbitMQ.Client.BasicProperties

projects/RabbitMQ.Client/client/api/AsyncDefaultBasicConsumer.cs

+3-10
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ public class AsyncDefaultBasicConsumer : IAsyncBasicConsumer
99
{
1010
private readonly HashSet<string> _consumerTags = new HashSet<string>();
1111

12-
/// <summary>
13-
/// Creates a new instance of an <see cref="AsyncDefaultBasicConsumer"/>.
14-
/// </summary>
15-
public AsyncDefaultBasicConsumer()
16-
{
17-
}
18-
1912
/// <summary>
2013
/// Constructor which sets the Channel property to the given value.
2114
/// </summary>
@@ -40,19 +33,19 @@ public string[] ConsumerTags
4033
/// <summary>
4134
/// Returns true while the consumer is registered and expecting deliveries from the broker.
4235
/// </summary>
43-
public bool IsRunning { get; protected set; }
36+
public bool IsRunning { get; private set; }
4437

4538
/// <summary>
4639
/// If our <see cref="IChannel"/> shuts down, this property will contain a description of the reason for the
4740
/// shutdown. Otherwise it will contain null. See <see cref="ShutdownEventArgs"/>.
4841
/// </summary>
49-
public ShutdownEventArgs? ShutdownReason { get; protected set; }
42+
public ShutdownEventArgs? ShutdownReason { get; private set; }
5043

5144
/// <summary>
5245
/// Retrieve the <see cref="IChannel"/> this consumer is associated with,
5346
/// for use in acknowledging received messages, for instance.
5447
/// </summary>
55-
public IChannel? Channel { get; set; }
48+
public IChannel Channel { get; private set; }
5649

5750
/// <summary>
5851
/// Called when the consumer is cancelled for reasons other than by a basicCancel:

projects/Test/Integration/TestAsyncConsumer.cs

+8-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public TestAsyncConsumer(ITestOutputHelper output)
5454
public async Task TestBasicRoundtripConcurrent()
5555
{
5656
AddCallbackExceptionHandlers();
57-
_channel.DefaultConsumer = new DefaultAsyncConsumer("_channel,", _output);
57+
_channel.DefaultConsumer = new DefaultAsyncConsumer(_channel, "_channel,", _output);
5858

5959
QueueDeclareOk q = await _channel.QueueDeclareAsync();
6060

@@ -147,7 +147,7 @@ public async Task TestBasicRoundtripConcurrent()
147147
public async Task TestBasicRoundtripConcurrentManyMessages()
148148
{
149149
AddCallbackExceptionHandlers();
150-
_channel.DefaultConsumer = new DefaultAsyncConsumer("_channel,", _output);
150+
_channel.DefaultConsumer = new DefaultAsyncConsumer(_channel, "_channel,", _output);
151151

152152
const int publish_total = 4096;
153153
const int length = 512;
@@ -205,7 +205,8 @@ public async Task TestBasicRoundtripConcurrentManyMessages()
205205
using (IChannel publishChannel = await publishConn.CreateChannelAsync())
206206
{
207207
AddCallbackExceptionHandlers(publishConn, publishChannel);
208-
publishChannel.DefaultConsumer = new DefaultAsyncConsumer("publishChannel,", _output);
208+
publishChannel.DefaultConsumer = new DefaultAsyncConsumer(publishChannel,
209+
"publishChannel,", _output);
209210
publishChannel.ChannelShutdown += (o, ea) =>
210211
{
211212
HandleChannelShutdown(publishChannel, ea, (args) =>
@@ -247,7 +248,8 @@ public async Task TestBasicRoundtripConcurrentManyMessages()
247248
using (IChannel consumeChannel = await consumeConn.CreateChannelAsync())
248249
{
249250
AddCallbackExceptionHandlers(consumeConn, consumeChannel);
250-
consumeChannel.DefaultConsumer = new DefaultAsyncConsumer("consumeChannel,", _output);
251+
consumeChannel.DefaultConsumer = new DefaultAsyncConsumer(consumeChannel,
252+
"consumeChannel,", _output);
251253
consumeChannel.ChannelShutdown += (o, ea) =>
252254
{
253255
HandleChannelShutdown(consumeChannel, ea, (args) =>
@@ -722,7 +724,8 @@ private class DefaultAsyncConsumer : AsyncDefaultBasicConsumer
722724
private readonly string _logPrefix;
723725
private readonly ITestOutputHelper _output;
724726

725-
public DefaultAsyncConsumer(string logPrefix, ITestOutputHelper output)
727+
public DefaultAsyncConsumer(IChannel channel, string logPrefix, ITestOutputHelper output)
728+
: base(channel)
726729
{
727730
_logPrefix = logPrefix;
728731
_output = output;

projects/Test/Integration/TestAsyncConsumerOperationDispatch.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public async Task TestChannelShutdownDoesNotShutDownDispatcher()
182182

183183
private class ShutdownLatchConsumer : AsyncDefaultBasicConsumer
184184
{
185-
public ShutdownLatchConsumer()
185+
public ShutdownLatchConsumer(IChannel channel) : base(channel)
186186
{
187187
Latch = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
188188
DuplicateLatch = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
@@ -211,7 +211,7 @@ public override Task HandleChannelShutdownAsync(object channel, ShutdownEventArg
211211
public async Task TestChannelShutdownHandler()
212212
{
213213
string q = await _channel.QueueDeclareAsync();
214-
var consumer = new ShutdownLatchConsumer();
214+
var consumer = new ShutdownLatchConsumer(_channel);
215215

216216
await _channel.BasicConsumeAsync(q, true, consumer);
217217
await _channel.CloseAsync();

0 commit comments

Comments
 (0)