Skip to content

Commit 865dced

Browse files
committed
Code refactor
1 parent c7c60fe commit 865dced

File tree

1 file changed

+13
-34
lines changed

1 file changed

+13
-34
lines changed

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

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ namespace RabbitMQ.Client.Impl
3636
{
3737
internal class RecordedConsumer : IRecordedConsumer
3838
{
39+
private readonly AutorecoveringModel _model;
40+
3941
public RecordedConsumer(AutorecoveringModel model, string queue, string consumerTag)
4042
{
4143
if (model is null)
@@ -44,7 +46,7 @@ public RecordedConsumer(AutorecoveringModel model, string queue, string consumer
4446
}
4547
else
4648
{
47-
Model = model;
49+
_model = model;
4850
}
4951

5052
if (queue is null)
@@ -55,7 +57,7 @@ public RecordedConsumer(AutorecoveringModel model, string queue, string consumer
5557
{
5658
if (queue == string.Empty)
5759
{
58-
Queue = model.CurrentQueue;
60+
Queue = _model.CurrentQueue;
5961
}
6062
else
6163
{
@@ -73,27 +75,23 @@ public RecordedConsumer(AutorecoveringModel model, string queue, string consumer
7375
}
7476
}
7577

76-
public AutorecoveringModel Model { get; }
78+
public AutorecoveringModel Model
79+
{
80+
get { return _model; }
81+
}
82+
83+
public string Queue { get; set; }
84+
public string ConsumerTag { get; set; }
7785
public IDictionary<string, object> Arguments { get; set; }
7886
public bool AutoAck { get; set; }
79-
public IBasicConsumer Consumer { get; set; }
80-
public string ConsumerTag { get; set; }
8187
public bool Exclusive { get; set; }
82-
public string Queue { get; set; }
88+
public IBasicConsumer Consumer { get; set; }
8389

8490
public string Recover(IModel channelToUse)
8591
{
86-
string queueName = Queue;
87-
if (string.IsNullOrEmpty(queueName))
88-
{
89-
// https://www.rabbitmq.com/amqp-0-9-1-reference.html#domain.queue-name
90-
queueName = channelToUse.CurrentQueue;
91-
}
92-
93-
ConsumerTag = channelToUse.BasicConsume(queueName, AutoAck,
92+
ConsumerTag = channelToUse.BasicConsume(Queue, AutoAck,
9493
ConsumerTag, false, Exclusive,
9594
Arguments, Consumer);
96-
9795
return ConsumerTag;
9896
}
9997

@@ -115,29 +113,10 @@ public RecordedConsumer WithConsumer(IBasicConsumer value)
115113
return this;
116114
}
117115

118-
public RecordedConsumer WithConsumerTag(string value)
119-
{
120-
if (string.IsNullOrEmpty(value))
121-
{
122-
throw new System.ArgumentNullException(nameof(value));
123-
}
124-
else
125-
{
126-
ConsumerTag = value;
127-
}
128-
return this;
129-
}
130-
131116
public RecordedConsumer WithExclusive(bool value)
132117
{
133118
Exclusive = value;
134119
return this;
135120
}
136-
137-
public RecordedConsumer WithQueue(string value)
138-
{
139-
Queue = value ?? throw new System.ArgumentNullException(nameof(value));
140-
return this;
141-
}
142121
}
143122
}

0 commit comments

Comments
 (0)