-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathservice.go
More file actions
45 lines (34 loc) · 953 Bytes
/
service.go
File metadata and controls
45 lines (34 loc) · 953 Bytes
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 (
"context"
messagebus "github.com/vardius/message-bus"
)
// Handler function
type Handler interface{}
// Payload of the message
type Payload []byte
// Service allows to subscribe/publish messages
type Service interface {
Publish(ctx context.Context, topic string, payload Payload)
Subscribe(topic string, fn Handler) error
Unsubscribe(topic string, fn Handler) error
Close(topic string)
}
type service struct {
bus messagebus.MessageBus
}
func newService(maxConcurrentCalls int) Service {
return &service{messagebus.New(maxConcurrentCalls)}
}
func (s *service) Publish(ctx context.Context, topic string, p Payload) {
s.bus.Publish(topic, ctx, p)
}
func (s *service) Subscribe(topic string, fn Handler) error {
return s.bus.Subscribe(topic, fn)
}
func (s *service) Unsubscribe(topic string, fn Handler) error {
return s.bus.Unsubscribe(topic, fn)
}
func (s *service) Close(topic string) {
s.bus.Close(topic)
}