Skip to content

Instantly share code, notes, and snippets.

@asim
Created June 13, 2016 10:50
Show Gist options
  • Save asim/31584c6da274b6f92960a1eb664d748c to your computer and use it in GitHub Desktop.
Save asim/31584c6da274b6f92960a1eb664d748c to your computer and use it in GitHub Desktop.
package main
import (
"log"
"github.com/micro/go-micro"
"github.com/micro/foo/handler"
"github.com/micro/foo/subscriber"
example "github.com/micro/foo/proto/example"
)
func main() {
// New Service
service := micro.NewService(
micro.Name("go.micro.srv.foo"),
micro.Version("latest"),
)
// Register Handler
example.RegisterExampleHandler(service.Server(), new(handler.Example))
// Register Struct as Subscriber
service.Server().Subscribe(
service.Server().NewSubscriber("topic.go.micro.srv.foo", new(subscriber.Example)),
)
// Register Function as Subscriber
service.Server().Subscribe(
service.Server().NewSubscriber("topic.go.micro.srv.foo", subscriber.Handler),
)
// Initialise service
service.Init()
// Run service
if err := service.Run(); err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment