-
Notifications
You must be signed in to change notification settings - Fork 3
/
consumableEvent.go
37 lines (32 loc) · 1003 Bytes
/
consumableEvent.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
package bunnify
import (
"encoding/json"
"time"
)
// Metadata holds the metadata of an event.
type Metadata struct {
ID string `json:"id"`
CorrelationID string `json:"correlationId"`
Timestamp time.Time `json:"timestamp"`
}
// DeliveryInfo holds information of original queue, exchange and routing keys.
type DeliveryInfo struct {
Queue string
Exchange string
RoutingKey string
}
// ConsumableEvent[T] represents an event that can be consumed.
// The type parameter T specifies the type of the event's payload.
type ConsumableEvent[T any] struct {
Metadata
DeliveryInfo DeliveryInfo
Payload T
}
// unmarshalEvent is used internally to unmarshal a PublishableEvent
// this way the payload ends up being a json.RawMessage instead of map[string]interface{}
// so that later the json.RawMessage can be unmarshal to ConsumableEvent[T].Payload.
type unmarshalEvent struct {
Metadata
DeliveryInfo DeliveryInfo
Payload json.RawMessage `json:"payload"`
}