-
Notifications
You must be signed in to change notification settings - Fork 0
/
nats.go
45 lines (37 loc) · 934 Bytes
/
nats.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 nats
import (
"time"
"github.com/micro/go-micro/client"
"github.com/micro/go-micro/registry"
"github.com/micro/go-micro/selector"
"github.com/micro/go-micro/selector/cache"
"github.com/micro/go-micro/server"
"github.com/micro/go-plugins/registry/nats"
defaults "github.com/pydio/cells/common/micro"
"github.com/spf13/viper"
)
func Enable() {
addr := viper.GetString("registry_address")
r := nats.NewRegistry(
registry.Addrs(addr),
)
q := 1
if defaults.RuntimeIsCluster() {
q = 0
}
defaults.DefaultStartupRegistry = nats.NewRegistry(
registry.Addrs(addr),
registry.Timeout(4*time.Second),
nats.Quorum(q),
)
s := cache.NewSelector(selector.Registry(r))
defaults.InitServer(func() server.Option {
return server.Registry(r)
})
defaults.InitClient(func() client.Option {
return client.Selector(s)
}, func() client.Option {
return client.Registry(r)
})
registry.DefaultRegistry = r
}