Skip to content

Commit 22d8a58

Browse files
committed
Ensure RecordedConsumer has a ConsumerTag
1 parent 0ad240b commit 22d8a58

File tree

3 files changed

+45
-24
lines changed

3 files changed

+45
-24
lines changed

projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -661,22 +661,11 @@ public override string ToString()
661661

662662
public void UnregisterModel(AutorecoveringModel model)
663663
{
664-
lock (_models)
665-
{
666-
_models.Remove(model);
667-
}
668-
}
669-
670-
public void UnregisterModel(AutorecoveringModel model, bool shouldDeleteRecordedConsumers)
671-
{
672-
if (shouldDeleteRecordedConsumers)
664+
lock (_recordedEntitiesLock)
673665
{
674-
lock (_recordedEntitiesLock)
666+
foreach (string ct in model.ConsumerTags)
675667
{
676-
foreach (string ct in model.ConsumerTags)
677-
{
678-
DeleteRecordedConsumer(ct);
679-
}
668+
DeleteRecordedConsumer(ct);
680669
}
681670
}
682671

projects/RabbitMQ.Client/client/impl/AutorecoveringModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ public void Close(ushort replyCode, string replyText, bool abort)
466466
}
467467
finally
468468
{
469-
_connection.UnregisterModel(this, true);
469+
_connection.UnregisterModel(this);
470470
}
471471
}
472472

@@ -483,7 +483,7 @@ public void Close(ShutdownEventArgs reason, bool abort)
483483
}
484484
finally
485485
{
486-
_connection.UnregisterModel(this, true);
486+
_connection.UnregisterModel(this);
487487
}
488488
}
489489

@@ -1191,7 +1191,7 @@ public string BasicConsume(
11911191

11921192
string resultConsumerTag = _delegate.BasicConsume(queue, autoAck, consumerTag, noLocal,
11931193
exclusive, arguments, consumer);
1194-
RecordedConsumer rc = new RecordedConsumer(this, queue).
1194+
RecordedConsumer rc = new RecordedConsumer(this, queue, resultConsumerTag).
11951195
WithConsumer(consumer).
11961196
WithExclusive(exclusive).
11971197
WithAutoAck(autoAck).

projects/RabbitMQ.Client/client/impl/RecordedConsumer.cs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,42 @@
2929
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
3030
//---------------------------------------------------------------------------
3131

32+
using System;
3233
using System.Collections.Generic;
3334

3435
namespace RabbitMQ.Client.Impl
3536
{
3637
internal class RecordedConsumer
3738
{
38-
public RecordedConsumer(AutorecoveringModel model, string queue)
39+
public RecordedConsumer(AutorecoveringModel model, string queue, string consumerTag)
3940
{
40-
Model = model;
41-
Queue = queue;
41+
if (model == null)
42+
{
43+
throw new ArgumentNullException(nameof(model));
44+
}
45+
else
46+
{
47+
Model = model ?? throw new ArgumentNullException(nameof(model));
48+
}
49+
50+
if (string.IsNullOrEmpty(queue))
51+
{
52+
throw new ArgumentNullException(nameof(consumerTag));
53+
}
54+
else
55+
{
56+
Queue = queue;
57+
}
58+
59+
if (string.IsNullOrEmpty(consumerTag))
60+
{
61+
throw new ArgumentNullException(nameof(consumerTag));
62+
}
63+
else
64+
{
65+
ConsumerTag = consumerTag;
66+
}
67+
4268
}
4369

4470
public AutorecoveringModel Model { get; }
@@ -60,7 +86,6 @@ public string Recover(IModel channelToUse)
6086

6187
public RecordedConsumer WithArguments(IDictionary<string, object> value)
6288
{
63-
Arguments = value;
6489
return this;
6590
}
6691

@@ -72,13 +97,20 @@ public RecordedConsumer WithAutoAck(bool value)
7297

7398
public RecordedConsumer WithConsumer(IBasicConsumer value)
7499
{
75-
Consumer = value;
100+
Consumer = value ?? throw new System.ArgumentNullException(nameof(value));
76101
return this;
77102
}
78103

79104
public RecordedConsumer WithConsumerTag(string value)
80105
{
81-
ConsumerTag = value;
106+
if (string.IsNullOrEmpty(value))
107+
{
108+
throw new System.ArgumentNullException(nameof(value));
109+
}
110+
else
111+
{
112+
ConsumerTag = value;
113+
}
82114
return this;
83115
}
84116

@@ -90,7 +122,7 @@ public RecordedConsumer WithExclusive(bool value)
90122

91123
public RecordedConsumer WithQueue(string value)
92124
{
93-
Queue = value;
125+
Queue = value ?? throw new System.ArgumentNullException(nameof(value));
94126
return this;
95127
}
96128
}

0 commit comments

Comments
 (0)