forked from pydio/cells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nats.go
46 lines (38 loc) · 970 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
46
package nats
import (
"fmt"
microbroker "github.com/micro/go-micro/broker"
"github.com/micro/go-micro/client"
"github.com/micro/go-micro/server"
"github.com/micro/go-plugins/broker/nats"
defaults "github.com/pydio/cells/common/micro"
"github.com/pydio/cells/common/micro/broker"
"github.com/pydio/cells/common/registry"
"github.com/spf13/viper"
)
// Enable the nats broker
func Enable() {
addr := viper.GetString("broker_address")
b := broker.NewBroker(
nats.NewBroker(microbroker.Addrs(addr)),
broker.BeforeDisconnect(func() error {
s, err := registry.ListRunningServices()
if err != nil {
return err
}
if len(s) > 0 {
return fmt.Errorf("services are still running")
}
return nil
}),
)
defaults.InitServer(func() server.Option {
return server.Broker(b)
})
defaults.InitClient(func() client.Option {
return client.Broker(b)
})
microbroker.DefaultBroker = b
// Establishing connectin
microbroker.Connect()
}