Git Product home page Git Product logo

cloudevents-sdk-cpp's Introduction

Build Status

C++ SDK for CloudEvents

This SDK is still a work in progress.

The CloudEvent class (generated from protobuf) is based on this open PR to the CloudEvent spec from JemDay.

The PubsubMessage class (generated from protobuf) is based on Google API.

This is not an officially supported Google product.

User Guide

More example use cases are available in header files as comments. The only files that you will directly import and use are in //v1/protocol_binding/.

Setup

Install Bazel Build System

Instuctions found in Bazel documentation.

Import SDK as a Bazel package in WORKSPACE

In //WORKSPACE

# TODO (#63) : Update README to create Bazel target to master repo once merged

git_repository(
    name = "cloudevents_cpp_sdk",
    commit = "20c9855c11bc66efcc6e086571477bb69870be1d",
    remote = "https://github.com/michlee1337/cloudevents-sdk-cpp/tree/binder-all.v2",
)

Set up the build dependencies

Specify any binders needed as a bazel target dependency.

To use PubsubBinder:

cc_binary(
    ...
    deps = [
        ...
        "@cloudevents_cpp_sdk/protocol_binding:pubsub_binder_lib",
    ],
)

To use HttpReqBinder or HttpResBinder:

cc_binary(
    ...
    deps = [
        ...
        "@cloudevents_cpp_sdk/protocol_binding:http_binder_lib",
    ],
)

Binding a CloudEvent to a Protocol-Message in Binary-ContentMode

Import the header file and use XBinder

// import the header for the binder
#include "//v1/protocol_binding/pubsub_binder.h"

using ::google::pubsub::v1::PubsubMessage;
using ::cloudevents::binder::PubsubBinder;
using ::cloudevents_absl::StatusOr;

// create a CloudEvent
CloudEvent my_cloud_event;
my_cloud_event.set_id("my_id");
my_cloud_event.set_source("my_source");
my_cloud_event.set_spec_version("1.0");
my_cloud_event.set_type("my_type");
my_cloud_event.set_binary_data("1010");

// Initialize the binder
PubsubBinder pubsub_binder;

// Create the Message
StatusOr<PubsubMessage> bind = pubsub_binder.Bind(my_cloud_event);

// Check no errors
if (!bind.ok()) {
  std::cerr << bind.status();
}

// unwrap message
PubsubMessage usable_message = *bind;

Binding a CloudEvent to a Protocol-Message in Structured-ContentMode

Import the header file and use Format and XBinder

// import the header for the binder
#include "//v1/protocol_binding/pubsub_binder.h"

using ::google::pubsub::v1::PubsubMessage;
using ::cloudevents::binder::PubsubBinder
using ::cloudevents::format::Format
using ::cloudevents_absl::StatusOr;

// create a CloudEvent
CloudEvent my_cloud_event;
my_cloud_event.set_id("my_id");
my_cloud_event.set_source("my_source");
my_cloud_event.set_spec_version("1.0");
my_cloud_event.set_type("my_type");
my_cloud_event.set_binary_data("1010");

// initialize the binder
PubsubBinder pubsub_binder;

// specify the EventFormat to be used and create the Message
StatusOr<PubsubMessage> bind = pubsub_binder.Bind(my_cloud_event, Format::kJson);

// check no errors
if (!bind.ok()) {
  std::cerr << bind.status();
}

// unwrap message
PubsubMessage usable_message = *bind;

Unbind a CloudEvent from a Protocol-Message

// import the header for the binder of the protocol message you're working with
#include "//v1/protocol_binding/pubsub_binder.h"

using ::google::pubsub::v1::PubsubMessage;
using ::cloudevents::binder::Binder
using ::cloudevents_absl::StatusOr;

PubsubMessage my_pusub_msg = ...; // However you get this message

// initialize the binder
PubsubBinder pubsub_binder;

// create the CloudEvent
StatusOr<CloudEvent> unbind = pubsub_binder.Unbind(my_pusub_msg);

// check no errors
if (!unbind.ok()) {
  std::cerr << unbind.status();
}

// unwrap cloudevent
CloudEvent cloud_event = *unbind;

Samples

Run-able code samples are available in the /samples folder.

Run

  1. Create executable
    bazel build //sample:create_event
  2. Run executable
    bazel-bin/sample/create_event

File Structure

All logic related to implementing version 1 of the CloudEvent spec can be found in //v1.

  • All logic for Protocol Bindings can be found in the subfolder //v1/protocol_binding.
  • All logic for Event Formats can be found in the subfolder //v1/event_format.

cloudevents-sdk-cpp's People

Contributors

ashley-sheng avatar hrasadi avatar michlee1337 avatar yaronkoller avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cloudevents-sdk-cpp's Issues

Convert serializations to variables of appropriate CE Type:

To be considered and designed.

Currently, all attribute values are assumed to be CE strings.

  • Should we try to convert them to CE types somehow?
  • Should that logic be handled by CE Util or individual formatters/ binders?
  • Is there a general logic that can be applied across formatters/ binders?

Move CloudEvents-related constexpr to CeUtil

Expected Behavior

Constants related to CloudEvents that are used across formatters and binders should be in a separate util.

Actual Behavior

Constants related to CloudEvents used by Json Formatter are currently declared in json formatter.

Create CloudEventBuilder class

Expected Behavior

Have a CloudEventBuilder class that can be used as an abstraction layer to create new CloudEvents

Actual Behavior

To create a CloudEvent, you have to directly access the CloudEvent members (generated via spec.proto).

Steps to Reproduce the Problem

The current method of creation can be seen in the file //samples/create_event.cc

Enable Setting Optional and Extension Attributes in CloudEvent

Expected Behavior

Should be able to add optional and extension attributes as defined by the
cloud event v1 spec
when creating a cloud event.

Actual Behavior

Only required attributes are currently supported.

Steps to Reproduce the Problem

The current method to create an event and the attributes supported can be seen in the file //samples/create_event.cc.

Better separation of concerns in Binder

Expected Behavior

Binder specializations only for getters/ setters for protocols.

Actual Behavior

BindBinary() and UnbindBinary() contain repeated logic across specializations

Set up CI Tests for third party libs after Travis branch is merged

Expected Behavior

Travis will run tests in //third_party/ as well

Actual Behavior

The config file in .travisyml currently will only run tests under //protocol/ because the third party folder is not merged into main yet.

Requires Further Clarification

Do proto files require tests as well?

Switch to official absl::StatusOr when released

Expected Behavior

SDK uses a bazel target to Abseil in order to use absl::StatusOr.

Actual Behavior

SDK copy/pastes code for absl::StatusOr into //third_party/statusor/

Steps to Reproduce the Problem

Check the //third_party/statusor/ folder

Support Any data in creating event

Expected Behavior

Any arbitrary object can be used as input for CloudEvent data.

Actual Behavior

Only strings and bytes can be used as input for CloudEvent data.

Steps to Reproduce the Problem

  1. bazel build //samples:create_event
  2. bazel-bin/samples/create_event
  3. When prompted to provide a data type, specify "other".

Support Any data

Expected Behavior

Formatters can convert a protobuf::Any and Binders can bind a protobuf::Any

Actual Behavior

An absl::UnimplementedError() is raised

Encapsulate validity checks for CloudEvent

Expected Behavior

All checking for whether a CloudEvent is valid is in one place.

Actual Behavior

Each marshaller and binder has its own checks.

Steps to Reproduce the Problem

json_marshaller.cc and pubsub_binder.cc both contain checks for whether a CloudEvent is valid.

Specifications

As of 15.07.20

Use external lib to validate URIs

Expected Behavior

An external library is used to validate URIs

Actual Behavior

A Regex expression is used to validate URIs

Steps to Reproduce the Problem

View //v1/util/cloud_events_util.cc#L70, in the SetMetadata() code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.