This repository has been archived by the owner on Mar 14, 2024. It is now read-only.
/
envelope.go
97 lines (80 loc) · 2.8 KB
/
envelope.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package endpoint
import (
"github.com/jmalloc/ax"
"github.com/jmalloc/ax/ident"
opentracing "github.com/opentracing/opentracing-go"
)
// AttemptID uniquely identifies an attempt to process a message.
type AttemptID struct {
ident.ID
}
// GenerateAttemptID generates a new unique identifier for a processing attempt.
func GenerateAttemptID() AttemptID {
var id AttemptID
id.GenerateUUID()
return id
}
// ParseAttemptID parses s into an attempt ID and returns it. It returns an
// error if s is empty.
func ParseAttemptID(s string) (AttemptID, error) {
var id AttemptID
err := id.Parse(s)
return id, err
}
// MustParseAttemptID parses s into an attempt ID and returns it. It panics if
// s is empty.
func MustParseAttemptID(s string) AttemptID {
var id AttemptID
id.MustParse(s)
return id
}
// InboundEnvelope is a specialization of ax.Envelope for messages that are
// received by an endpoint.
//
// Inbound envelopes traverse an InboundPipeline.
type InboundEnvelope struct {
ax.Envelope
// SourceEndpoint is the endpoint that sent the message.
SourceEndpoint string
// AttemptID uniquely identifies the attempt to process this message.
AttemptID AttemptID
// AttemptCount is the number of times that an attempt has been made to process
// this message.
//
// Messages may be retried after a failure handling the message, or if
// an endpoint crashes, for example. Not all transports support an attempt
// count. If the attempt count is unknown, it is set to zero.
//
// The attempt count may be reset if a message is manually re-queued after
// being rejected by the retry policy.
AttemptCount uint
// SpanContext is the tracing context that was propagated with the message.
SpanContext opentracing.SpanContext
}
// OutboundEnvelope is a specialization of ax.Envelope for messages that are
// sent by an endpoint.
//
// Outbound envelopes traverse an OutboundPipeline.
type OutboundEnvelope struct {
ax.Envelope
// Operation is the operation to be performed on the message. It dictates
// how the message is sent by the transport.
Operation Operation
// DestinationEndpoint is the endpoint to which the message is sent when
// Operation is OpSendUnicast. The field is ignored for other operations.
DestinationEndpoint string
// SpanContext is the tracing context to propagate with the message.
SpanContext opentracing.SpanContext
}
// Operation is an enumeration of transport operations that can be performed
// in order to send an outbound message.
type Operation int
const (
// OpSendUnicast is an outbound transport operation that sends a message to
// a specific endpoint as determined by the outbound message's
// DestinationEndpoint property.
OpSendUnicast Operation = iota
// OpSendMulticast is an outbound transport operation that sends a message
// to all of its subscribers.
OpSendMulticast
)