forked from hellofresh/goengine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.go
42 lines (32 loc) · 1015 Bytes
/
message.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 goengine
import (
"time"
"github.com/google/uuid"
"github.com/hellofresh/goengine/v2/metadata"
)
type (
// UUID is a 128 bit (16 byte) Universal Unique IDentifier as defined in RFC4122
UUID = uuid.UUID
// Message is a interface describing a message.
// A message can be a command, domain event or some other type of message.
Message interface {
// UUID returns the identifier of this message
UUID() UUID
// CreatedAt returns the created time of the message
CreatedAt() time.Time
// Payload returns the payload of the message
Payload() interface{}
// Metadata return the message metadata
Metadata() metadata.Metadata
// WithMetadata Returns new instance of the message with key and value added to metadata
WithMetadata(key string, value interface{}) Message
}
)
// GenerateUUID creates a new random UUID or panics
func GenerateUUID() UUID {
return uuid.New()
}
// IsUUIDEmpty returns true if the UUID is empty
func IsUUIDEmpty(id UUID) bool {
return id == uuid.Nil
}