Skip to content

amzapi/protoc-gen-go-asynq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

protoc-gen-go-asynq

generate protobuf for asynq payload.

usage

1. install protoc-gen-go-asynq

# first install protobuf, then install
go get -d google.golang.org/protobuf/cmd/protoc-gen-go
go get -d google.golang.org/grpc/cmd/protoc-gen-go-grpc

# install protoc-gen-go-asynq
go install github.com/amzapi/protoc-gen-go-asynq@latest

2. copy asynq/asynq.proto to your project

3. define task proto

syntax = "proto3";

package example;

// import copy asynq.proto
import "asynq/asynq.proto";
import "google/protobuf/empty.proto";

option go_package = ".;example";
option java_multiple_files = true;
option java_package = "example";

service User {
    rpc CreateUser(CreateUserPayload) returns (google.protobuf.Empty) {
        option (asynq.task) = {
            typename: "user:create" // define asynq.task typename, it is unique.
        };
    };
    rpc UpdateUser(UpdateUserPayload) returns (google.protobuf.Empty) {
        option (asynq.task) = {
            typename: "user:update"
        };
    };
}

message CreateUserPayload {
    string name = 1;
}

message UpdateUserPayload {
    string name = 1;
}

4. generate

protoc --proto_path=. \
       --proto_path=./{copy_dir} \
       --go_out=paths=source_relative:. \
       --go-asynq_out=paths=source_relative:. \
       example/example.proto

5. implement

Don't care about encode/decode, you just implement your define method.