-
Notifications
You must be signed in to change notification settings - Fork 1
/
broker_helper.go
53 lines (43 loc) · 2.06 KB
/
broker_helper.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
package broker
import (
"context"
"git.golaxy.org/core/service"
"git.golaxy.org/core/util/option"
"strings"
)
// Publish the data argument to the given topic. The data argument is left untouched and needs to be correctly interpreted on the receiver.
func Publish(servCtx service.Context, ctx context.Context, topic string, data []byte) error {
return Using(servCtx).Publish(ctx, topic, data)
}
// Subscribe will express interest in the given topic pattern. Use option EventHandler to handle message events.
func Subscribe(servCtx service.Context, ctx context.Context, pattern string, settings ...option.Setting[SubscriberOptions]) (ISubscriber, error) {
return Using(servCtx).Subscribe(ctx, pattern, settings...)
}
// SubscribeSync will express interest in the given topic pattern.
func SubscribeSync(servCtx service.Context, ctx context.Context, pattern string, settings ...option.Setting[SubscriberOptions]) (ISyncSubscriber, error) {
return Using(servCtx).SubscribeSync(ctx, pattern, settings...)
}
// SubscribeChan will express interest in the given topic pattern.
func SubscribeChan(servCtx service.Context, ctx context.Context, pattern string, settings ...option.Setting[SubscriberOptions]) (IChanSubscriber, error) {
return Using(servCtx).SubscribeChan(ctx, pattern, settings...)
}
// Flush will perform a round trip to the server and return when it receives the internal reply.
func Flush(servCtx service.Context, ctx context.Context) error {
return Using(servCtx).Flush(ctx)
}
// GetDeliveryReliability return message delivery reliability.
func GetDeliveryReliability(servCtx service.Context) DeliveryReliability {
return Using(servCtx).GetDeliveryReliability()
}
// GetMaxPayload return max payload bytes.
func GetMaxPayload(servCtx service.Context) int64 {
return Using(servCtx).GetMaxPayload()
}
// GetSeparator return topic path separator.
func GetSeparator(servCtx service.Context) string {
return Using(servCtx).GetSeparator()
}
// Path return topic path.
func Path(servCtx service.Context, elems ...string) string {
return strings.Join(elems, GetSeparator(servCtx))
}