Havret / dotnet-activemq-artemis-client

.NET Client for Apache ActiveMQ Artemis
https://havret.github.io/dotnet-activemq-artemis-client/
MIT License
64 stars 11 forks source link

[ArtemisNetClient.Testing] Add support for filter expressions #452

Closed Havret closed 1 year ago

Havret commented 1 year ago

Feature description

Feature in action

var endpoint = Endpoint.Create("localhost", 5672, "guest", "guest");
using var testKit = new TestKit(endpoint);

var connectionFactory = new ConnectionFactory();
await using var connection = await connectionFactory.CreateAsync(endpoint);

var address = "test_address";
await using var redMessageConsumer = await connection.CreateConsumerAsync(new ConsumerConfiguration
{
    Address = address,
    RoutingType = RoutingType.Multicast,
    FilterExpression = "color = 'red'"
});

await testKit.SendMessageAsync(address, new Message("blue") { ApplicationProperties = { ["color"] = "blue" } });
await testKit.SendMessageAsync(address, new Message("red") { ApplicationProperties = { ["color"] = "red" } });

var redMessage = await redMessageConsumer.ReceiveAsync();

redMessage.ApplicationProperties.TryGetValue<string>("color", out var color); // color=red

Describe alternatives you've considered

One could directly interact with an actual ActiveMQ Artemis broker, but this would defeat the purpose of having a testing library in the first place.

Additional context

By introducing this feature, users will have a seamless and more accurate testing experience, ensuring that the behavior in the testing environment closely matches the production environment.