|
| 1 | +// This source code is dual-licensed under the Apache License, version |
| 2 | +// 2.0, and the Mozilla Public License, version 2.0. |
| 3 | +// |
| 4 | +// The APL v2.0: |
| 5 | +// |
| 6 | +//--------------------------------------------------------------------------- |
| 7 | +// Copyright (c) 2007-2024 Broadcom. All Rights Reserved. |
| 8 | +// |
| 9 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +// you may not use this file except in compliance with the License. |
| 11 | +// You may obtain a copy of the License at |
| 12 | +// |
| 13 | +// https://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +// |
| 15 | +// Unless required by applicable law or agreed to in writing, software |
| 16 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +// See the License for the specific language governing permissions and |
| 19 | +// limitations under the License. |
| 20 | +//--------------------------------------------------------------------------- |
| 21 | +// |
| 22 | +// The MPL v2.0: |
| 23 | +// |
| 24 | +//--------------------------------------------------------------------------- |
| 25 | +// This Source Code Form is subject to the terms of the Mozilla Public |
| 26 | +// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 27 | +// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 28 | +// |
| 29 | +// Copyright (c) 2007-2024 Broadcom. All Rights Reserved. |
| 30 | +//--------------------------------------------------------------------------- |
| 31 | + |
| 32 | +using System.Collections.Generic; |
| 33 | +using System.Threading.Tasks; |
| 34 | +using RabbitMQ.Client; |
| 35 | +using RabbitMQ.Client.Events; |
| 36 | +using Xunit; |
| 37 | +using Xunit.Abstractions; |
| 38 | + |
| 39 | +namespace Test.Integration.ConnectionRecovery |
| 40 | +{ |
| 41 | + public class TestQueueRecoveryWithArguments : TestConnectionRecoveryBase |
| 42 | + { |
| 43 | + public TestQueueRecoveryWithArguments(ITestOutputHelper output) : base(output) |
| 44 | + { |
| 45 | + } |
| 46 | + |
| 47 | + [Fact] |
| 48 | + public async Task TestQueueRecoveryWithDlxArgument_RabbitMQUsers_hk5pJ4cKF0c() |
| 49 | + { |
| 50 | + string tdiWaitExchangeName = GenerateExchangeName(); |
| 51 | + string tdiRetryExchangeName = GenerateExchangeName(); |
| 52 | + string testRetryQueueName = GenerateQueueName(); |
| 53 | + string testQueueName = GenerateQueueName(); |
| 54 | + |
| 55 | + await _channel.ExchangeDeclareAsync(exchange: tdiWaitExchangeName, |
| 56 | + type: ExchangeType.Topic, durable: true, autoDelete: false, arguments: null); |
| 57 | + await _channel.ExchangeDeclareAsync(exchange: tdiRetryExchangeName, |
| 58 | + type: ExchangeType.Topic, durable: true, autoDelete: false, arguments: null); |
| 59 | + |
| 60 | + var arguments = new Dictionary<string, object> |
| 61 | + { |
| 62 | + { "x-dead-letter-exchange", "tdi.retry.exchange" }, |
| 63 | + { "x-dead-letter-routing-key", "QueueTest" } |
| 64 | + }; |
| 65 | + |
| 66 | + await _channel.QueueDeclareAsync(testRetryQueueName, durable: false, exclusive: false, autoDelete: false, arguments); |
| 67 | + |
| 68 | + arguments["x-dead-letter-exchange"] = "tdi.wait.exchange"; |
| 69 | + arguments["x-dead-letter-routing-key"] = "QueueTest"; |
| 70 | + |
| 71 | + await _channel.QueueDeclareAsync(testQueueName, durable: false, exclusive: false, autoDelete: false, arguments); |
| 72 | + |
| 73 | + arguments.Remove("x-dead-letter-exchange"); |
| 74 | + arguments.Remove("x-dead-letter-routing-key"); |
| 75 | + |
| 76 | + await _channel.QueueBindAsync(testRetryQueueName, tdiWaitExchangeName, testQueueName); |
| 77 | + |
| 78 | + await _channel.QueueBindAsync(testQueueName, tdiRetryExchangeName, testQueueName); |
| 79 | + |
| 80 | + var consumerAsync = new EventingBasicConsumer(_channel); |
| 81 | + await _channel.BasicConsumeAsync(queue: testQueueName, autoAck: false, consumer: consumerAsync); |
| 82 | + |
| 83 | + await CloseAndWaitForRecoveryAsync(); |
| 84 | + |
| 85 | + QueueDeclareOk q0 = await _channel.QueueDeclarePassiveAsync(testRetryQueueName); |
| 86 | + Assert.Equal(testRetryQueueName, q0.QueueName); |
| 87 | + |
| 88 | + QueueDeclareOk q1 = await _channel.QueueDeclarePassiveAsync(testQueueName); |
| 89 | + Assert.Equal(testQueueName, q1.QueueName); |
| 90 | + } |
| 91 | + } |
| 92 | +} |
0 commit comments