-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemitter.go
42 lines (36 loc) · 1.04 KB
/
emitter.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
package hevent
import (
"context"
"errors"
validation "github.com/go-ozzo/ozzo-validation/v4"
"github.com/kamva/hexa"
)
type (
// Emitter is the interface to emit events
Emitter interface {
// Emit sends event to the channel.
// context can be nil.
// dont forget to validate the event here.
Emit(context.Context, *Event) (msgID string, err error)
hexa.Shutdownable
}
// Event is the event to send.
Event struct {
Key string // required, can use to specify partition number.(see pulsar docs)
Channel string
ReplyChannel string // optional (use if need to reply the response)
// It will encode using either protobuf,json,... encoder(relative to config of emitter).
// Dont forget that your emitter encoder and event receivers decoder should match with each other.
Payload interface{}
}
)
func (e Event) Validate() error {
if e.Channel == "" {
return errors.New("event channel is required")
}
if e.Key == "" {
return errors.New("event key is required")
}
return nil
}
var _ validation.Validatable = &Event{}