-
Notifications
You must be signed in to change notification settings - Fork 3
/
event_bus.go
54 lines (48 loc) · 1.96 KB
/
event_bus.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
// Copyright 2021 Monoskope Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package eventsourcing
import (
"context"
)
// EventBusConnector can open and close connections.
type EventBusConnector interface {
// Close closes the underlying connections
Close() error
}
// EventBusPublisher publishes events on the underlying message bus.
type EventBusPublisher interface {
EventBusConnector
// PublishEvent publishes the event on the bus.
PublishEvent(context.Context, Event) error
}
// EventBusConsumer notifies registered handlers on incoming events on the underlying message bus.
type EventBusConsumer interface {
EventBusConnector
// Matcher returns a new implementation specific matcher.
Matcher() EventMatcher
// AddHandler adds a handler for events matching one of the given EventMatcher.
AddHandler(context.Context, EventHandler, ...EventMatcher) error
// AddWorker behave similar to AddHandler but distributes events among the handlers with the same
// work queue name according to the competing consumers pattern.
AddWorker(context.Context, EventHandler, string, ...EventMatcher) error
}
// EventMatcher is an interface used to define what events should be consumed
type EventMatcher interface {
// Any matches any event.
Any() EventMatcher
// MatchEventType matches a specific event type.
MatchEventType(eventType EventType) EventMatcher
// MatchAggregate matches a specific aggregate type.
MatchAggregateType(aggregateType AggregateType) EventMatcher
}