JasperFx / wolverine

Supercharged .NET server side development!
https://wolverinefx.net
MIT License
1.22k stars 131 forks source link

Inconsistent auto provisioning with Azure Service Bus subscription rule filters #1021

Open BrianVallelunga opened 1 month ago

BrianVallelunga commented 1 month ago

Wolverine treats SQL filters differently from Correlation filters when auto-provisioning.

I have a couple of subscriptions with filters configured in Azure. We're using Pulumi to keep our infrastructure in code and it works well and one of my subscriptions has a SQL filter rule applied to it. Another has a correlation filter rule applied.

I was noticing that after provisioning the environment my SQL filter was being removed, but my correlation filter was not. At first I thought this was a problem with Azure, but then realized Wolverine was deleting my SQL filter, but not my correlation filter.

In neither case was I specifying the filters in the Wolverine code and just assumed they were ignored:

let registerHandler (wolverineOptions: WolverineOptions) =
    wolverineOptions
        .ListenToAzureServiceBusSubscription("my-subscription")
        .FromTopic("my-topic")
        .InteropWith(CustomAzureServiceBusMapper<MyEventType>())
    |> ignore

Aside from the subscription name, both handlers had the same registration code. I've since added the subscription filter to my registration.

let registerHandler (wolverineOptions: WolverineOptions) =
    wolverineOptions
        .ListenToAzureServiceBusSubscription("my-subscription")
        .FromTopic("my-topic")
        .ConfigureSubscriptionRule(fun rule ->
            rule.Filter <- SqlRuleFilter("MyMessageType = 'X' OR MyMessageType = 'Y'"))
        .InteropWith(CustomAzureServiceBusMapper<MyEventType>())
    |> ignore

I'm not sure if Wolverine should ignore existing rule filters or wipe them out, but the behavior should at least be consistent between filter types.

Xzelsius commented 3 weeks ago

@BrianVallelunga here is the code which adjust subscription rules: https://github.com/JasperFx/wolverine/blob/cb49f977d2ca33ccb72ac3f592f8528eb6f644e9/src/Transports/Azure/Wolverine.AzureServiceBus/Internal/AzureServiceBusSubscription.cs#L106

Back when I implemented this my intention was that Wolverine is the Master of the subscription. That's the reason it wipes out all other rules besides the default one. The filter can be adjusted, so if you want your rule (non-default name) to stay either adjust the default rule Wolverine knows about or Wolverine needs to adapt some things. But Wolverine might not work correctly if there are foreign rules active which prevents messages that Wolverine expects to receive.

But in the end, @jeremydmiller needs to decide what behavior he wants. I can just offer my help regarding ASB.