Skip to content

Instantly share code, notes, and snippets.

@asim
Created February 7, 2020 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asim/2bc81ea4ee08a0723cc7251d5a5f51e3 to your computer and use it in GitHub Desktop.
Save asim/2bc81ea4ee08a0723cc7251d5a5f51e3 to your computer and use it in GitHub Desktop.
package main

import (
        "context"
        "fmt"

        "github.com/micro/go-micro/v2"
        _ "github.com/micro/go-plugins/broker/grpc/v2"
)

func main() {
        service := micro.NewService(
                micro.Name("foobar"),
        )
        service.Init()

        fmt.Println("broker is", service.Options().Broker.String())

        sub := service.Server().NewSubscriber("Cruft", func(ctx context.Context, msg *string) error {
                fmt.Println("some cruft")
                return nil
        })

        service.Server().Subscribe(sub)


        service.Run()
}
go run x.go --broker=grpc 
broker is grpc
2020-02-07 17:23:45 Starting [service] foobar
2020-02-07 17:23:45 Server [grpc] Listening on [::]:42509
2020-02-07 17:23:45 Broker Listening on [::]:42823
2020-02-07 17:23:45 Broker [grpc] Connected to [::]:42823
2020-02-07 17:23:45 Registry [mdns] Registering node: foobar-cfa405e9-aebf-4abd-ba20-2037a6859d10
2020-02-07 17:23:45 Subscribing to topic: Cruft
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment