-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.go
56 lines (44 loc) · 1.7 KB
/
messages.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
package pubsub
import (
"context"
)
type (
// Message is an interface to manage pubsub messages relevant data
// It has to represent the message payload and can include relevant information
// from message attributes. It is used to abstract messages type and organisation
// allowing any struct to be converted to a pubsub message while masking
// some pubsub logic.
Message interface {
// ID of the message in the service provider.
ID() interface{}
// Data payload.
Data() []byte
// Metadata are all the tags witch can identify the message and group it with others but are not
// relevant as information.
Metadata() map[string]string
// Ack acknowledges message.
Ack()
// Nack refuses to acknowledge message.
Nack()
}
// Envelop is an interface to link a golang object representing your
// relevant data to a Message interface. It act as a DTO and
// use Filter method to get relevant filtering data.
Envelop interface {
// ToPubsubMessage converts the envelop to JSON representative byte table.
// Used before emitting message to queue.
ToPubsubMessage() (Message, error)
// FromPubsubMessage set envelop data from message json payload.
FromPubsubMessage(msg Message) error
// Filter returns a logical map to filter value. The key as to match the expected pubsub metadata key
// while the value represent the expected value to filter.
Filter() MessageFilter
// New generates a new empty envelop.
// Used form message reception.
New() Envelop
}
// MessageCallback enforces callback function type on reception.
MessageCallback func(ctx context.Context, msg Message)
// MessageFilter represents filtering data for message reception.
MessageFilter map[string]string
)