Repository navigation
Automatically unwrap pub/sub CloudEvent #576
Description
Activity
@artursouza : Any thoughts on this?
The .Net SDK drops some cloud events attribute to make it easier to use. The Java SDK has a different approach. We can make a change to make it easier to convert java.util.Map to a type - it is already possible today via Jackson. Maybe a method in CloudEvent that will deserialize
datato a particular type.- addedgood first issueGood for newcomersGood for newcomerskind/enhancementNew feature or requestNew feature or requesttriaged/resolvedItems triaged and readyItems triaged and ready
on Jul 9, 2021 I did a quick & dirty PoC by copying the
CloudEventclass from the Dapr SDK into my application and making it generic. I declared thedatainstance field as typeTThe default serializer, Jackson, handled that perfectly well, giving me aCloudEvent<MyPayload>with access to the deserializedMyPayloadvariable. That is a relatively small change, I believe it doesn't even break backward compatibility (although it'd be good to double-check that).If you feel @artursouza that this could be a good way forward, I'll be more than happy to provide a pull request so we can discuss the implementation.
Hi, Im also very inerested in this :-) I dont have much experience in developing distributed system but hope I can help with something going forward. @artursouza please see #575 (comment)
Thanks.
I did a quick & dirty PoC by copying the
CloudEventclass from the Dapr SDK into my application and making it generic. I declared thedatainstance field as typeTThe default serializer, Jackson, handled that perfectly well, giving me aCloudEvent<MyPayload>with access to the deserializedMyPayloadvariable. That is a relatively small change, I believe it doesn't even break backward compatibility (although it'd be good to double-check that).If you feel @artursouza that this could be a good way forward, I'll be more than happy to provide a pull request so we can discuss the implementation.
Please, send this PR. I am happy to take that in. Just keep in mind that changes must be backwards compatible.
Automatically unwrap pub/sub CloudEvent
Background
In the Dapr SDK for .NET, one can configure the SDK to automatically unwrap CloudEvents that an application receives over pub/sub using
app.UseCloudEvents().The Dapr SDK for Java, however, only lets you receive a
CloudEvent. It provides access to the underlying message usinggetData, but that method returns anObject. According to the specs, this can be a JSON object or string. This means in practice it can be anything - for complex types, it will most likely be ajava.util.Map.Proposal
It would be cool if the SDK for Java would allow to unwrap a
CloudEventin the same way as the SDK for .NET does.Alternatives
As an alternative, if the
CloudEventclass would be a generic class with one type parameter that describes the type of thedata, field, it would at least make it a lot easier to unwrap theCloudEventby declaring it of the right type and then callinggetData()on it. I did a quick & dirty PoC by copying theCloudEventclass into my application and making it generic, and Jackson (the default serializer) seems to handle perfectly well.