Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion projects/RabbitMQ.Client/client/impl/RecordedBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,15 @@ public override string ToString()

public RecordedBinding WithArguments(IDictionary<string, object> value)
{
Arguments = value;
if (value is null)
{
Arguments = null;
}
else
{
Arguments = new Dictionary<string, object>(value);
}

return this;
}

Expand Down
10 changes: 9 additions & 1 deletion projects/RabbitMQ.Client/client/impl/RecordedConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ public string Recover(IModel channelToUse)

public RecordedConsumer WithArguments(IDictionary<string, object> value)
{
Arguments = value;
if (value is null)
{
Arguments = null;
}
else
{
Arguments = new Dictionary<string, object>(value);
}

return this;
}

Expand Down
10 changes: 9 additions & 1 deletion projects/RabbitMQ.Client/client/impl/RecordedExchange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ public override string ToString()

public RecordedExchange WithArguments(IDictionary<string, object> value)
{
Arguments = value;
if (value is null)
{
Arguments = null;
}
else
{
Arguments = new Dictionary<string, object>(value);
}

return this;
}

Expand Down
10 changes: 9 additions & 1 deletion projects/RabbitMQ.Client/client/impl/RecordedQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ protected string NameToUseForRecovery

public RecordedQueue WithArguments(IDictionary<string, object> value)
{
Arguments = value;
if (value is null)
{
Arguments = null;
}
else
{
Arguments = new Dictionary<string, object>(value);
}

return this;
}

Expand Down
63 changes: 58 additions & 5 deletions projects/Unit/TestConnectionRecovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -744,10 +744,17 @@ public void TestRecoveringConsumerHandlerOnConnection()
[Test]
public void TestRecoveringConsumerHandlerOnConnection_EventArgumentsArePassedDown()
{
var myArgs = new Dictionary<string, object> { { "first-argument", "some-value" } };
const string key = "first-argument";
const string value = "some-value";

IDictionary<string, object> arguments = new Dictionary<string, object>
{
{ key, value }
};

string q = Model.QueueDeclare(GenerateQueueName(), false, false, false, null).QueueName;
var cons = new EventingBasicConsumer(Model);
string expectedCTag = Model.BasicConsume(cons, q, arguments: myArgs);
string expectedCTag = Model.BasicConsume(cons, q, arguments: arguments);

bool ctagMatches = false;
bool consumerArgumentMatches = false;
Expand All @@ -757,14 +764,15 @@ public void TestRecoveringConsumerHandlerOnConnection_EventArgumentsArePassedDow
// passed to a CallbackExceptionHandler, instead of failing the test. Instead, we have to do this trick
// and assert in the test function.
ctagMatches = args.ConsumerTag == expectedCTag;
consumerArgumentMatches = (string)args.ConsumerArguments["first-argument"] == "some-value";
args.ConsumerArguments["first-argument"] = "event-handler-set-this-value";
consumerArgumentMatches = (string)args.ConsumerArguments[key] == value;
};

CloseAndWaitForRecovery();
Assert.That(ctagMatches, Is.True, "expected consumer tag to match");
Assert.That(consumerArgumentMatches, Is.True, "expected consumer arguments to match");
Assert.That(myArgs, Does.ContainKey("first-argument").WithValue("event-handler-set-this-value"));
Assert.That(arguments.ContainsKey(key), Is.True);
string actualVal = (string)arguments[key];
Assert.That(actualVal, Is.EqualTo(value));
}

[Test]
Expand Down Expand Up @@ -1687,6 +1695,51 @@ void MessageReceived(object sender, BasicDeliverEventArgs e)
}
}

[Test]
public void TestQueueRecoveryWithDlxArgument_RabbitMQUsers_hk5pJ4cKF0c()
{
string tdiWaitExchangeName = GenerateExchangeName();
string tdiRetryExchangeName = GenerateExchangeName();
string testRetryQueueName = GenerateQueueName();
string testQueueName = GenerateQueueName();

Model.ExchangeDeclare(exchange: tdiWaitExchangeName,
type: ExchangeType.Topic, durable: true, autoDelete: false, arguments: null);
Model.ExchangeDeclare(exchange: tdiRetryExchangeName,
type: ExchangeType.Topic, durable: true, autoDelete: false, arguments: null);

var arguments = new Dictionary<string, object>
{
{ "x-dead-letter-exchange", "tdi.retry.exchange" },
{ "x-dead-letter-routing-key", "QueueTest" }
};

Model.QueueDeclare(testRetryQueueName, durable: false, exclusive: false, autoDelete: false, arguments);

arguments["x-dead-letter-exchange"] = "tdi.wait.exchange";
arguments["x-dead-letter-routing-key"] = "QueueTest";

Model.QueueDeclare(testQueueName, durable: false, exclusive: false, autoDelete: false, arguments);

arguments.Remove("x-dead-letter-exchange");
arguments.Remove("x-dead-letter-routing-key");

Model.QueueBind(testRetryQueueName, tdiWaitExchangeName, testQueueName);

Model.QueueBind(testQueueName, tdiRetryExchangeName, testQueueName);

var consumerAsync = new EventingBasicConsumer(Model);
Model.BasicConsume(queue: testQueueName, autoAck: false, consumer: consumerAsync);

CloseAndWaitForRecovery();

QueueDeclareOk q0 = Model.QueueDeclarePassive(testRetryQueueName);
Assert.AreEqual(testRetryQueueName, q0.QueueName);

QueueDeclareOk q1 = Model.QueueDeclarePassive(testQueueName);
Assert.AreEqual(testQueueName, q1.QueueName);
}

internal bool SendAndConsumeMessage(string queue, string exchange, string routingKey)
{
using (var ch = Conn.CreateModel())
Expand Down