# README
pubsubhandler.go
This package makes it easier to develop PubSub push handlers for Protobuf encoded messages.
It also includes tracing and logging support.
go get "github.com/MottoStreaming/pubsubhandler.go"
main.go:
func main() {
handler := pubsubhandler.NewHandler(slog.Default())
// Register handler for topic `CM_Orders`
handler.RegisterHandler(
"CM_Orders",
(*orders.Updated)(nil).ProtoReflect().Type(),
func(ctx context.Context, m proto.Message) error {
order := orderFromProto(m.(*orders.Updated))
// Handle message
return orderService.Update(ctx, order)
},
)
// Register more topics and handlers here
// Now you can use handler as http.Handler
mux := http.NewServeMux()
// You can register PubSub push handler with endpoint
// `/pubsub/CM_Orders`
mux.Handle("/pubsub", handler)
}
# Functions
NewHandler creates a new handler.
# Structs
No description provided by the author
No description provided by the author
PubSubMessage is the payload of a Pub/Sub event.
# Type aliases
MessageHandler is a function that handles protobuf message.
MessageWithMetadataHandler is a function that handles protobuf message along with its metadata (attributes, publish_time).