-
Notifications
You must be signed in to change notification settings - Fork 3
/
integration.go
75 lines (66 loc) · 2.6 KB
/
integration.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
package dogma
import (
"context"
)
// An IntegrationMessageHandler integrates a Dogma application with external and
// non-message-based systems.
//
// The engine does not keep any state for integration handlers.
type IntegrationMessageHandler interface {
// Configure describes the handler's configuration to the engine.
Configure(IntegrationConfigurer)
// HandleCommand handles a command, typically by invoking some external API.
//
// It MAY optionally record events that describe the outcome of the command.
//
// The engine MAY call this method concurrently from separate goroutines or
// operating system processes.
HandleCommand(context.Context, IntegrationCommandScope, Command) error
}
// A IntegrationConfigurer configures the engine for use with a specific
// integration message handler.
type IntegrationConfigurer interface {
// Identity configures the handler's identity.
//
// n is a short human-readable name. It MUST be unique within the
// application at any given time, but MAY change over the handler's
// lifetime. It MUST contain solely printable, non-space UTF-8 characters.
// It must be between 1 and 255 bytes (not characters) in length.
//
// k is a unique key used to associate engine state with the handler. The
// key SHOULD NOT change over the handler's lifetime. k MUST be an RFC 4122
// UUID, such as "5195fe85-eb3f-4121-84b0-be72cbc5722f".
//
// Use of hard-coded literals for both values is RECOMMENDED.
Identity(n string, k string)
// Routes configures the engine to route certain message types to and from
// the handler.
//
// Integration handlers support the HandlesCommand() and RecordsEvent()
// route types.
Routes(...IntegrationRoute)
// Disable prevents the handler from receiving any messages.
//
// The engine MUST NOT call any methods other than Configure() on a disabled
// handler.
//
// Disabling a handler is useful when the handler's configuration prevents
// it from operating, such as when it's missing a required dependency,
// without requiring the user to conditionally register the handler with the
// application.
Disable(...DisableOption)
}
// IntegrationCommandScope performs engine operations within the context of a
// call to the HandleCommand() method of an [IntegrationMessageHandler].
type IntegrationCommandScope interface {
// RecordEvent records the occurrence of an event.
RecordEvent(Event)
// Log records an informational message.
Log(format string, args ...any)
}
// IntegrationRoute describes a message type that's routed to or from a
// [IntegrationMessageHandler].
type IntegrationRoute interface {
Route
isIntegrationRoute()
}