-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
45 lines (35 loc) · 915 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"log"
"github.com/micro/go-micro"
"github.com/micro/go-micro/server"
"time"
"udian.me/goods/handler"
myService "udian.me/goods/service"
"udian.me/goods/subscriber"
goods "udian.me/proto/goods"
_ "github.com/micro/go-plugins/broker/nsq"
_ "github.com/micro/go-plugins/registry/etcd"
)
var (
topic = "topic.go.micro.srv.goods"
)
func main() {
// New Service
service := micro.NewService(
micro.Name("go.micro.srv.v1.goods"),
micro.Version("latest"),
micro.RegisterTTL(time.Second*30),
micro.RegisterInterval(time.Second*15),
)
// di service
myService.InitService(service)
// Register Handler
goods.RegisterGoodsHandler(service.Server(), new(handler.Goods))
micro.RegisterSubscriber(topic, service.Server(), new(subscriber.Goods), server.SubscriberQueue("consumer"))
service.Init()
// Run service
if err := service.Run(); err != nil {
log.Fatal(err)
}
}