Path: redb-route/tests/redb.Route.Tests.Amqp/AmqpStand.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/AmqpStand.cs ---- using Amqp; using Amqp.Framing; using redb.Route.Tests.Conformance; using AmqpMessage = global::Amqp.Message; namespace redb.Route.Tests.Amqp; /// /// The AMQP 1.0 stand: ActiveMQ Artemis at localhost:5673 (admin/admin), reached through AMQPNetLite directly, not /// through the connector. Its container, when names it, is broken with /// ; the broker is ready when its AMQP acceptor takes connections again. /// public sealed class AmqpStand : IConnectorStand { /// The variable that names the Artemis container a test may restart. public const string ContainerVariable = "REDB_TEST_AMQP_CONTAINER"; /// The broker's address for the stand's own client. public const string BrokerAddress = "amqp://admin:admin@localhost:5673"; private static readonly global::Amqp.Types.Symbol QueueCapability = new("queue"); /// The stand of this process. public static AmqpStand Instance { get; } = new(); private AmqpStand() { } /// public BrokerFault? Fault { get; } = BrokerFault.FromEnvironment(ContainerVariable, "nc", "-z", "localhost", "5673"); /// public TimeSpan Wait { get; } = BrokerFault.DefaultWait; /// public async Task PutAsync(string destination, string body, CancellationToken ct = default) { var connection = await Connection.Factory.CreateAsync(new Address(BrokerAddress)).WaitAsync(ct); try { var session = new Session(connection); var sender = new SenderLink(session, $"stand-sender-{Guid.NewGuid():N}", new Target { Address = destination, Capabilities = [QueueCapability] }, null); await sender.SendAsync(new AmqpMessage(body) { Properties = new Properties { MessageId = Guid.NewGuid().ToString("N") } }); await sender.CloseAsync(); } finally { await connection.CloseAsync(); } } /// public async Task> DrainAsync(string destination, TimeSpan wait, CancellationToken ct = default) { var bodies = new List(); var connection = await Connection.Factory.CreateAsync(new Address(BrokerAddress)).WaitAsync(ct); try { var session = new Session(connection); var receiver = new ReceiverLink(session, $"stand-receiver-{Guid.NewGuid():N}", new Source { Address = destination, Capabilities = [QueueCapability] }, null); var next = wait; while (await receiver.ReceiveAsync(next) is { } message) { receiver.Accept(message); bodies.Add(message.Body?.ToString() ?? ""); next = TimeSpan.FromMilliseconds(500); } await receiver.CloseAsync(); } finally { await connection.CloseAsync(); } return bodies; } }