protoevents

package module
v0.0.0-...-af94976 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 9 Imported by: 0

README

protoevents

protoevents is a protoc extension used to dispatch events upon successful completion of grpc method calls. As of now it only supports Go.

Usecases

It enables loosely coupled event driven architecture for various background tasks such as,

  • sending emails
  • sending sms
  • sending notifications
  • collecting payments
  • trigerring integrations

Usage

For a protobuf definition like this,

syntax = "proto3";

package example;

import "events/events.proto";

option go_package = "github.com/srikrsna/protoevents/example;expb";

service ExampleService {
  rpc ExampleFiringRpc(ExampleRpcRequest) returns (ExampleRpcResponse) {
    option (events.fire) = true;
  }

  rpc ExampleSilentRpc(ExampleRpcRequest) returns (ExampleRpcResponse);
}

message ExampleRpcRequest {}

message ExampleRpcResponse {}
package main

func main() {
    grpc.NewServer(grpc.ChainUnaryInterceptor(
        protoevents.NewInterceptor(protoevents.Options{
            Dispatcher:  // TODO,
            ErrorLogger: // TODO,
	    },
    )))
}

Upon each succesful completion of the rpc tagged with (events.fires) = true an event will be dispatched with request, response, and full method name.

The dispatcher is configurable. Currently it supports the following dispatchers and encoding formats

Dispatchers:

gocloud.dev/pubsub

Encoding:

protobuf

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewInterceptor

func NewInterceptor(opt Options) grpc.UnaryServerInterceptor

Types

type Dispatcher

type Dispatcher interface {
	Dispatch(context.Context, *Event) error
}

type ErrorLogger

type ErrorLogger interface {
	Log(context.Context, *Event, error)
}

type Event

type Event struct {
	Id   string
	Type string

	Request  protoreflect.ProtoMessage
	Response protoreflect.ProtoMessage
}

type Options

type Options struct {
	Dispatcher Dispatcher

	ErrorLogger ErrorLogger

	Preprocess bool
}

Directories

Path Synopsis
dispatchers
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL