This Dart package provides developers with the tools necessary to easily interact with Google Cloud Events, facilitating the integration of Google Cloud services into Dart and Flutter applications. By abstracting the complexity of event handling, this SDK enables you to subscribe to, manage, and dispatch events from Google Cloud services with minimal effort.
- Serialize and Deserialize Cloud Events From Protobuf Format You can use this library with the Dart server framework of your choice in order to handle EventArc events in a Cloud Run instance.
- TODO Should this repo should follow the SDK requirements so that it can be officially recognized?
Add google_cloud_events to your pubspec.yaml file:
dependencies:
google_cloudevents_dart: ^1.0.0Then, run pub get or flutter pub get to install the package.
For an example of using this package in a server application, see the example in this package.
This library's Dart files are generated from protobuf definitions. To refresh these files with the latest specifications, use the scripts provided in the scripts directory. The cloudevents directory, used during this process, is temporarily created and is excluded from Git.
TLDR:
dart run scripts/remove_cloudevent_protos.dart && \
dart run scripts/clone_cloudevent_protos.dart && \
dart run scripts/generate_cloudevent_protos.dart && \
dart run scripts/generate_cloudevent_library.dart && \
dart format libPrerequisites: The refresh scripts require the following command-line tools to be installed and available in your system's PATH:
gitsh- The Protocol Buffer compiler (defaults to
protoc; its name/path can be specified as an argument in Step 2).
Note: On Windows, you need to run these scripts using an environment that provides these Unix-like utilities, such as Git Bash or Windows Subsystem for Linux (WSL).
Here's the typical workflow:
-
Clone Protobuf Definitions:
Run
dart run scripts/clone_cloudevent_protos.dartThis script clones the
googleapis/google-cloudeventsrepository into a localcloudeventsdirectory, which will contain the.protofiles. -
Generate Dart Files from Protobufs:
Run
dart run scripts/generate_cloudevent_protos.dart [optional_protoc_executable]This script generates Dart files from the
.protodefinitions. It executes helper scripts, invokes the Protocol Buffer compiler, and organizes the output files.The Protocol Buffer compiler executable can be provided as an argument and defaults to
protocif not specified. -
Generate Library Export Files:
Run
dart run scripts/generate_cloudevent_library.dartThis script analyzes the generated Dart files in
lib/srcand creates or updates the main library export files inlib. -
Format Generated Code:
Run
dart format libThis command formats the generated Dart files in the
libdirectory to ensure consistent code style.
Cleanup:
To remove the cloudevents directory (created in Step 1), for instance, after generation or to ensure a fresh clone:
Run dart run scripts/remove_cloudevent_protos.dart
This will delete the directory and its contents. To re-clone the protobuf definitions if needed, run Step 1 again.
For detailed documentation on all features and functionalities, please visit the following documentation.
- What Are Cloud Events? Cloud Events Describes the specificiation that Google Cloud Events is derived from.
- How Google Implements Cloud Events: The Google Cloud Events Format (Detailed) Describes the packet
- How Does Google Send a Cloud Event? Protocol Buffers The way that Google serializes the data that it sends to cloud event recievers. Bonus The object/event definitions are contained in this folder in the google-cloudevents repository.
- How To Use Google Cloud Events (Triggers and Recievers of Cloud Events in Google Cloud Platform): Event Driven Architectures With Eventarc and Eventarc Overview. One way that Google makes it easier to register triggers and recievers for Cloud Events in Google Cloud Platform (GCP).
- How To Deploy An Eventarc Reciever Service To Cloud Run. For now the easiest way to write a reciever in Dart looks like Cloud Run.
This SDK is released under the MIT License.
Special thanks to Very Good Ventures (VGV) for being leaders in Dart/Flutter development. We used the very_good_cli to help generate the boilerplate for this package. We also recommend trying dart_frog for developing your first dart server application.