Handling messages with a parent class doesn't create subscription rules

(Arley Pádua) #1

Currently I’m implementing a saga that is handling an event that is parent of two child events.
The storage used for the saga is SQL Server and the transport method of messages is Azure Service Bus.

Something like:

public class ParentEvent { ... }
public class ChildEvent1 : ParentEvent { ... }
public class ChildEvent2 : ParentEvent { ... }

And the saga:

public class MySaga : Saga<MySagaData>, IAmStartedByMessages<ParentEvent>

When I start my application I expected the installers to run and create a subscription rule for the parent event, but it is not happening.

When I switch the saga to IAmStartedByMessages<ChildEvent1> it creates the subscriptions rules as expected.

I also tested with interfaces:

public interface IParentEvent { ... }
public class ParentEvent : IParentEvent { ... }
public class ChildEvent1 : ParentEvent { ... }
public class ChildEvent2 : ParentEvent { ... }

And the saga handling the interface: IAmStartedByMessages<IParentEvent>, but it only works if I handle the child concrete type.

Is there any particular reason why this is not working ?

(Sean Feldman) #2

Hi Arley,

What topology are you using with Azure Service Bus transport?
If you’re on EndpointOriented topology, it doesn’t handle polimorphic events properly and requires a workaround documented in a sample availabel here.

For Forwarding topology, this should just work.

(Francesc Castells) #3

@SeanFeldman, @arleypadua and I work together. We are using Forwarding topology and I know that another colleague had the same issue. I believe the problem is only in creating the subscriptions only. If we subscribe to a concrete type or child type and run the application, the subscriptions and rules will be created. Then we can switch the code back to listen to the base class or interface and it will work.

(Sean Feldman) #4

Hi Francesc,

It should work. I have tried to reproduce the issue and could not. You could try the same using Polymorphic Events sample. You will need to replace EndpointOriented topology with Forwarding. Once you do, delete DerivedEventHandler to ensure there’s only BaseEventHandler. When done, you should be able to publish either BaseEvent or DerivedEvent and both will be handled by BaseEventHandler.

When subscribing to the base (Parent) event, created topology should be similar to the topology created by the sample (see below).

Could you please confirm the sample is working or not for you?
Thank you.

(Sean Feldman) #5

@fcastells have you had a chance to run the sample with the changes I’ve suggested?

(Francesc Castells) #6

Hi @SeanFeldman,
I finally managed to test this. I did as you said and it worked. Both by only registering to the base class and only registering to the child class. I did it with the same nuget versions that we are using, therefore, it is something in our code. We’ll need to figure out what it is…

(Sean Feldman) #7

Let the hunting games begin @fcastells! :slightly_smiling_face:
Jokes aside, if there’s anything can help, please let know.