Skip to content

Event Descriptions in Protobuf #28654

Description

@EliSauder

What language does this apply to?
If it's for proto2, proto3, or an edition? Any
If it's a generated code change, what programming language? NA

Describe the problem you are trying to solve.
Define event streaming schemas based on protobufs.

Describe the solution you'd like
Add something like an event keyword that would behave similarly to rpc. Something like:

service UserService {
  rpc GetUser(GetUserRequest) returns (User);
  rpc ListUsers(ListUsersRequest) returns (ListUsersResponse);
  rpc CreateUser(CreateUserRequest) returns (User);
  rpc UpdateUser(UpdateUserRequest) returns (User);
  rpc DeleteUser(DeleteUserRequest) returns (google.protobuf.Empty);

  event CreatedUser User;
  event UpdatedUser User;
  event DeletedUser DeletedUserEvent;
}

This would enable defining options for the events as will, something like a google.api.http but for events enabling the topic/stream to be defined.

Describe alternatives you've considered

  1. Utilizing a "Events" message
    The example above would look something like this:
message UserEvents {
  oneof events {
    User created = 1;
    User updated = 2;
    DeletedUserEvent deleted = 3;
  }
} 

This works, but creates some annoyances when working with linters and is fully dependent on naming schemes.

  1. Use service and rpc
    Use existing service and rpc ideas
service UserService {
  rpc GetUser(GetUserRequest) returns (User);
  rpc ListUsers(ListUsersRequest) returns (ListUsersResponse);
  rpc CreateUser(CreateUserRequest) returns (User);
  rpc UpdateUser(UpdateUserRequest) returns (User);
  rpc DeleteUser(DeleteUserRequest) returns (google.protobuf.Empty);

  rpc CreatedUserEvent(google.protobuf.Empty) returns (User);
  rpc UpdatedUserEvent(google.protobuf.Empty) returns (User);
  rpc DeletedUserEvent(google.protobuf.Empty) returns (DeletedUserEvent);
}

This has more issues than (1) since protoc tools will treat these events as methods (since they are) and you have the same linter and naming scheme issues from (1). 

**Additional context**
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestuntriagedauto added to all issues by default when created.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions