-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Whats the suggested way to declare strongly typed events? (And why is CloudEvent sealed?) #308
Comments
Even if In terms of what I'd do instead: I'd avoid implicit potentially-lossy operators, preferring methods for conversions - but other than that the way of creating a As for why it's a class and not a record: we could potentially have designed it for immutability from the start, but that certainly wasn't the case in v1, and while my changes for v2 were fairly significant, I think making them immutable would have been a much bigger change. (Note that the repo was started in 2018, two years before record types were available in C#...) |
Thanks a lot for the clarifications and feedback! They all make sense to me. It was a rough, very first attempt, not a final version. So as you said, the So the way I am understanding cloudevents spec right now is that there are 3 types of properties here: Auto generated properties:
Identification properties:
Payload:
(I guess we can argue about some of them being in the right place) On event declaration time, devs should only specify the identification properties:
On event instantiation time, devs should only specify the payload and subject:
On publishing time, infrastructure should convert it into a CloudEvent.
On receving time, infrastructure should parse the body to a CloudEvent, then map it to a strongly typed event.
The biggest issue I am facing is how to achieve the last part, without forcing to declare to many things in the I am starting to lean towards a code generator to generate the boilerplate code for the copy constructor. But any ideas are welcome! |
If you put a constructor in a common base type with a public record OrderCreatedEvent(... /* whatever you need here, if anything */) : BaseEvent<OrderInfo>
{
public OrderCreatedEvent(CloudEvent evt) : base(evt) {}
} The deserialization of the JSON to the |
Hi all,
I have bee working in event-driven architectures using RabbitMQ for the last years, and the approach, for relatively small products, is that the project that owns an event is declaring the event in a separate project like (oversimplifying):
A library receives the instance and serializes it all to publish it to RabbitMQ. And on the subscribing side, it uses the class definition to deserialize the string and pass it onto the subscription.
This allows all actors (publishers, subscribers, tests, etc) to use a single definition for a single event while freeing all the code from serialization, deserialization and casting.
I am looking to migrate this implementation to CloudEvents, so the first thing I thought about was:
But
CloudEvent
is sealed :(My first alternative is to declare my BaseEvent with operators to cast to and from
CloudEvent
:But before I move forward, I am double checking:
An additionally:
CloudEvent
sealed?Thanks
The text was updated successfully, but these errors were encountered: