1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-01-05 10:20:53 +02:00
go-micro/examples/event/srv/main.go
Asim Aslam d94936f6c9
v3 (#2104)
* v3

* revert plugins

* fixup some issues
2021-01-20 13:54:31 +00:00

34 lines
680 B
Go

package main
import (
"context"
"github.com/asim/go-micro/v3"
proto "github.com/asim/go-micro/v3/api/proto"
"github.com/asim/go-micro/v3/util/log"
)
// All methods of Event will be executed when a message is received
type Event struct{}
// Method can be of any name
func (e *Event) Process(ctx context.Context, event *proto.Event) error {
log.Logf("Received event %+v\n", event)
// do something with event
return nil
}
func main() {
service := micro.NewService(
micro.Name("user"),
)
service.Init()
// register subscriber
micro.RegisterSubscriber("go.micro.evt.user", service.Server(), new(Event))
if err := service.Run(); err != nil {
log.Fatal(err)
}
}