We have a hierarchy of event interfaces which all adds some properties, and I want to have a consumer (EventConsumer) which subscribe to messages on the highest level (IEvent). The consumer's responsibility is to store all events in a database. This database will serve as a history of everything happened in our distributed system (like an event source).
The hierarchy is something like this and only ConcreteEventX messages are published on the bus:
IEvent
ConcreteEvent1
IConcreteEvent2
ConcreteEvent2
What is the best way to get a json serialized object of the entire message from the message context (e.g. ConcreteEvent1)?
How can I get the name of the most concrete type/interface (ConcreteEvent1/IConcreteEvent) so that I can later on construct the events from the database (there is a SupportedMessageTypes which may be of use)?
The EventConsumer does not know all ConcreteEventX types as we cannot be sure that the EventConsumer runs in a process where all types are known.