Skip to content
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

How to specify type with metadata of pubsub? #772

Open
DanielYWoo opened this issue Aug 31, 2022 · 2 comments
Open

How to specify type with metadata of pubsub? #772

DanielYWoo opened this issue Aug 31, 2022 · 2 comments

Comments

@DanielYWoo
Copy link

DanielYWoo commented Aug 31, 2022

The CloudEvent spec says we can specify the type in the metadata. The SDK allows metadata customization when publishing an event as below

    Map<String, String> metadata = new HashMap<>();
    metadata.put("type", "com.test.user.created");
    Mono<Void> result = client.publishEvent("pubsub", "inbox", payload, metadata);
    result.block(Duration.ofSeconds(2));

But the type seems always be com.dapr.event.sent. I debug into the gRPC code down to protocol bufferserializeStringMapTo and I am pretty sure the type is correctly written to the sidecar via 50001.

Are there anything wrong here? And can I specify other metadata like metadata.rawPayload?

If I do a POST with curl, this works

curl -X POST http://myurl... -d {"specversion" : "1.0", "type" : "com.mytest", "source" : "testcloudeventspubsub", "subject" : "Cloud Events Test", "id" : "111111", "time" : "2021-08-02T09:00:00Z", "datacontenttype" : "application/cloudevents+json", "data" : {"orderId": "100"}}

So I guess this problem only occurs in gRPC. However, the SDK does not support HTTP for pub/sub, right?

@tanvigour
Copy link
Contributor

SDK has metadata.CONTENT_TYPE to customize the type. https://github.com/dapr/java-sdk/blob/master/sdk/src/main/java/io/dapr/client/domain/Metadata.java

@DanielYWoo
Copy link
Author

DanielYWoo commented Sep 3, 2022

SDK has metadata.CONTENT_TYPE to customize the type. https://github.com/dapr/java-sdk/blob/master/sdk/src/main/java/io/dapr/client/domain/Metadata.java

Thanks, @tanvigour , but I am not saying the media type in "content-type" or "datacontenttype", I am saying the "type" context attribute in CloudEvent spec. e.g, "user.created".

And it seems I cannot set extension context attributes (custom metadata), but the CloudSpec allows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants