Path: redb-route/tests/redb.Route.Tests.Amqp/AmqpReplyToBridgeTests.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Amqp/AmqpReplyToBridgeTests.cs ---- using redb.Route.Abstractions; using redb.Route.Amqp; using redb.Route.Core; namespace redb.Route.Tests.Amqp; /// /// A sender's reply-to does not travel across a bridge, as in Apache Camel's JMS: a message consumed with a reply-to and /// forwarded by an ordinary send goes out without it, unless the producer sets preserveMessageQos=true. The /// correlation id is carried; a request-reply producer sets its own reply-to. Expects ActiveMQ Artemis at /// localhost:5673 (admin/admin). /// [Trait("Category", "Integration")] public sealed class AmqpReplyToBridgeTests { private const string Connection = "host=localhost&port=5673&user=admin&password=admin"; /// /// Sends one message with the given reply-to and correlation id to an input address, bridges it by a route to an /// output address, and returns the headers the forwarded message arrived with. /// private static async Task> Bridge(string producerOptions, string? senderReplyTo, Action? routeStep = null) { var input = $"bridge.in.{Guid.NewGuid():N}"; var output = $"bridge.out.{Guid.NewGuid():N}"; var arrived = new TaskCompletionSource>(TaskCreationOptions.RunContinuationsAsynchronously); await using var context = new RouteContext(); context.AddComponent(new AmqpComponent()); context.AddRoutes(r => { r.From($"amqp://{input}?{Connection}") .Process(ex => routeStep?.Invoke(ex)) .To($"amqp://{output}?{Connection}{producerOptions}"); r.From($"amqp://{output}?{Connection}") .Process(ex => arrived.TrySetResult(new Dictionary(ex.In.Headers))); }); await context.Start(); // The sender: an ordinary send that names its reply address on purpose. var sender = context.GetEndpoint($"amqp://{input}?{Connection}&preserveMessageQos=true").CreateProducer(); await sender.Start(); var message = new Message("bridged"); message.Headers[AmqpHeaders.CorrelationId] = "corr-1"; if (senderReplyTo is not null) message.Headers[AmqpHeaders.ReplyTo] = senderReplyTo; await sender.Process(new Exchange(message)); await sender.Stop(); return await arrived.Task.WaitAsync(TimeSpan.FromSeconds(20)); } [Fact] public async Task A_forwarded_message_goes_out_without_the_senders_reply_to_and_keeps_its_correlation_id() { var forwarded = await Bridge(producerOptions: "", senderReplyTo: "sender.replies"); forwarded.Should().NotContainKey(AmqpHeaders.ReplyTo, "an ordinary send does not carry a sender's reply-to on"); forwarded[AmqpHeaders.CorrelationId]?.ToString().Should().Be("corr-1"); } [Fact] public async Task With_preserveMessageQos_the_forwarded_message_keeps_the_senders_reply_to() { var forwarded = await Bridge(producerOptions: "&preserveMessageQos=true", senderReplyTo: "sender.replies"); forwarded[AmqpHeaders.ReplyTo].Should().Be("sender.replies"); forwarded[AmqpHeaders.CorrelationId]?.ToString().Should().Be("corr-1"); } [Theory] [InlineData("", false)] [InlineData("&preserveMessageQos=true", true)] public async Task A_reply_to_header_set_by_the_route_follows_the_same_rule(string producerOptions, bool kept) { var forwarded = await Bridge(producerOptions, senderReplyTo: null, routeStep: ex => ex.In.Headers[AmqpHeaders.ReplyTo] = "route.named.replies"); if (kept) forwarded[AmqpHeaders.ReplyTo].Should().Be("route.named.replies"); else forwarded.Should().NotContainKey(AmqpHeaders.ReplyTo); } [Fact] public async Task A_request_reply_producer_sets_its_own_reply_to_over_a_forwarded_one() { var address = $"bridge.rpc.{Guid.NewGuid():N}"; await using var context = new RouteContext(); context.AddComponent(new AmqpComponent()); context.AddRoutes(r => r .From($"amqp://{address}?{Connection}") .Process(ex => ex.Out = new Message("pong"))); await context.Start(); var producer = context.GetEndpoint($"amqp://{address}?{Connection}&replyTo=true&timeout=15&preserveMessageQos=true") .CreateProducer(); await producer.Start(); try { var exchange = new Exchange(new Message("ping")); exchange.In.Headers[AmqpHeaders.ReplyTo] = "an.address.of.another.system"; await producer.Process(exchange); exchange.HasOut.Should().BeTrue("the reply came back to the producer's own reply address"); var body = exchange.Out!.Body is byte[] bytes ? System.Text.Encoding.UTF8.GetString(bytes) : exchange.Out.Body?.ToString(); body.Should().Be("pong"); } finally { await producer.Stop(); } } }