forked from pydio/cells
-
Notifications
You must be signed in to change notification settings - Fork 0
/
broker.go
59 lines (47 loc) · 1.47 KB
/
broker.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
47
48
49
50
51
52
53
54
55
56
57
58
59
package broker
import "github.com/micro/go-micro/broker"
type brokerwrap struct {
b broker.Broker
opts Options
}
// NewBroker wraps a standard broker but prevents it from disconnecting while there still is a service running
func NewBroker(b broker.Broker, opts ...Option) broker.Broker {
return &brokerwrap{b, newOptions(opts...)}
}
// Options wraps standard function
func (b *brokerwrap) Options() broker.Options {
return b.b.Options()
}
// Address wraps standard function
func (b *brokerwrap) Address() string {
return b.b.Address()
}
// Connect wraps standard function
func (b *brokerwrap) Connect() error {
return b.b.Connect()
}
// Disconnect handles the disconnection to the broker. It prevents it if there is a service that is still active
func (b *brokerwrap) Disconnect() error {
for _, o := range b.opts.beforeDisconnect {
if err := o(); err != nil {
return err
}
}
return b.b.Disconnect()
}
// Init wraps standard function
func (b *brokerwrap) Init(opts ...broker.Option) error {
return b.b.Init(opts...)
}
// Publish wraps standard function
func (b *brokerwrap) Publish(s string, m *broker.Message, opts ...broker.PublishOption) error {
return b.b.Publish(s, m, opts...)
}
// Publish wraps standard function
func (b *brokerwrap) Subscribe(s string, h broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) {
return b.b.Subscribe(s, h, opts...)
}
// Publish wraps standard function
func (b *brokerwrap) String() string {
return b.b.String()
}