question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Much harder with V2 than V1 to send binary CloudEvents

See original GitHub issue

I might be missing something, but it seems to me that it has become much harder to send binary CloudEvents with the V2 SDK, unless you happen to be using one of the small number of supported HTTP clients. In V1, I could write this:

Wire<String, String, String> wire = Marshallers.<Map<String, Object>>binary()
        .withEvent(() -> myCloudEvent)
        .marshal();

Then I basically just needed to copy wire.getHeaders() into the HTTP headers of the request and have wire.getPayload().get() be the HTTP body. That’s easy to do with pretty much any HTTP API.

With V2 it looks like I am out of luck if there isn’t already a MessageWriter defined for the specific HTTP API that I am using. It’s not that hard to make a MessageWriter by following the example of one of the existing ones, but it’s still about 50 lines of non-trivial code.

Could we have the simplicity of V1 back? Perhaps with a trivial MessageWriter implementation that just stashes the HTTP headers in a Map<String, String> and the body in a byte[] or whatever, which is more or less what the old Wire did. It’s nice that the supported HTTP clients are so easy to use, but it seems to be at the cost of making anything else much harder.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
matejvasekcommented, Sep 1, 2020

@eamonnmcmanus I tried to create generic http binding https://github.com/cloudevents/sdk-java/pull/225, please look at it.

0reactions
matejvasekcommented, Sep 1, 2020

It the PR #225 I added generic Message(Reader|Writer) and factory methods to instantiate them + some convenience static methods:

public static CloudEvent readCloudEvent(Map<String,String> headers, byte[] body) ;
public static void writeCloudEventBinary(CloudEvent cloudEvent, BiConsumer<String, String> putHeader, Consumer<byte[]> putBody);
public static void writeCloudEventStructured(CloudEvent cloudEvent, EventFormat eventFormat, BiConsumer<String, String> putHeader, Consumer<byte[]> putBody);
public static void writeCloudEventStructured(CloudEvent cloudEvent, String eventFormat, BiConsumer<String, String> putHeader, Consumer<byte[]> putBody);
Read more comments on GitHub >

github_iconTop Results From Across the Web

handling of datacontenttype is inconsistent #558 - GitHub
The JSON Format spec says that "If the implementation determines that the type of data is Binary, the value MUST be represented as...
Read more >
Cloud Events - Object Partners
The cloudevents specification provides a standardized way of describing events that is meant to be consistent, accessible, and portable.
Read more >
CloudEvents - Intro, Deep-Dive a... Doug Davis, Clemens ...
Join us for Kubernetes Forums Seoul, Sydney, Bengaluru and Delhi - learn more at kubecon.io Don't miss KubeCon + CloudNativeCon 2020 events ...
Read more >
CloudEvents: Intro, Status and the Future... - YouTube
Scott Nichols, Chainguard The CloudEvents specification is one of those ... we'll then look at what's been going on since we shipped v1.0 ......
Read more >
How CloudEvents and AsyncAPI can help enable Event ...
Binary - This is where the CloudEvent meta is held in HTTP headers ... event data rather than passing the actual event data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found