Skip to content

Automatically unwrap pub/sub CloudEvent #576

Description

@mthmulders

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 using getData, but that method returns an Object. 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 a java.util.Map.

Proposal

It would be cool if the SDK for Java would allow to unwrap a CloudEvent in the same way as the SDK for .NET does.

Alternatives

As an alternative, if the CloudEvent class would be a generic class with one type parameter that describes the type of the data, field, it would at least make it a lot easier to unwrap the CloudEvent by declaring it of the right type and then calling getData() on it. I did a quick & dirty PoC by copying the CloudEvent class into my application and making it generic, and Jackson (the default serializer) seems to handle perfectly well.

Activity

  1. tanvigour commented on Jul 7, 2021

    @tanvigour
    Contributor

    @artursouza : Any thoughts on this?

  2. artursouza commented on Jul 9, 2021

    @artursouza
    Contributor

    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 data to a particular type.

  3. mthmulders commented on Jul 11, 2021

    @mthmulders
    ContributorAuthor

    I did a quick & dirty PoC by copying the CloudEvent class from the Dapr SDK into my application and making it generic. I declared the data instance field as type T The default serializer, Jackson, handled that perfectly well, giving me a CloudEvent<MyPayload> with access to the deserialized MyPayload variable. 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.

  4. danp11 commented on Jul 16, 2021

    @danp11

    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.

  5. artursouza commented on Jul 29, 2021

    @artursouza
    Contributor

    I did a quick & dirty PoC by copying the CloudEvent class from the Dapr SDK into my application and making it generic. I declared the data instance field as type T The default serializer, Jackson, handled that perfectly well, giving me a CloudEvent<MyPayload> with access to the deserialized MyPayload variable. 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.

  6. added this to the v1.3 milestone on Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions