-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublisher.go
47 lines (38 loc) · 1.6 KB
/
publisher.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
package pubsub
import (
"context"
)
type (
// Publisher interface allow to build messages to be sent through pubsub instance.
Publisher interface {
// To indicates topic in witch we would like to send the message
// if topic is used for the first time, a connection will be created
// and kept alive regarding this topic.
// Call Clean method to clear all saved topic.
To(topics ...string) Publisher
// WithOption allows to configure locally a send call.
WithOption(opt interface{}) Publisher
// Send message to topics listed in Send instance. It will returns a SendResults interface
// witch you can safely discard if you don't need to check that your message
// was correctly sent.
Send(ctx context.Context, msg Envelop) (SendResults, error)
// Destroy has to be called at the end of life of the publisher instance to ensure all messages are correctly
// sent. Destroy method will only return after ensuring messages were sent or errored then it will
// destroy connection to pubsub instance definitively.
// Publisher cannot be used any more after Destroy.
Destroy()
}
// SendResults allows to manage publish results
SendResults interface {
// Results recovers send response and return the list of result corresponding Results structure.
// This is a locking process. Results will await server response before returning.
Results(ctx context.Context) Results
// OnResults will apply callback function when server respond.
OnResults(ctx context.Context, allback func(topic string, result Result))
}
Result struct {
ID string
Error error
}
Results map[string]Result
)