forked from Orange-Health/pubsublib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pubsub.go
32 lines (25 loc) · 929 Bytes
/
pubsub.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
package pubsub
type MessageHandler func(message string) error
var (
clients = []*Client{&Client{Provider: NoopProvider{}}}
)
// Client holds a reference to a Provider
type Client struct {
ServiceName string
Provider Provider
Middleware []Middleware
}
type Provider interface {
Publish(topicARN string, message interface{}, messageAttributes map[string]interface{}) error
PollMessages(queueURL string, handler MessageHandler) error
}
// SetClient sets the global pubsub client, useful in tests
func SetClient(cli *Client) {
clients = []*Client{cli}
}
// PublishHandler wraps a call to publish, for interception
type PublishHandler func(topicARN string, message interface{}, messageAttributes map[string]interface{}) error
// Middleware is an interface to provide subscriber and publisher interceptors
type Middleware interface {
PublisherMsgInterceptor(serviceName string, next PublishHandler) PublishHandler
}