-
Notifications
You must be signed in to change notification settings - Fork 0
/
bus.go
36 lines (31 loc) · 1.02 KB
/
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
package bus
import (
"context"
"github.com/vectrum-io/strongforce/pkg/serialization"
"time"
)
type Bus interface {
// Publish sends a new message to the bus. It must be added in order to ensure consistency
Publish(ctx context.Context, message *OutboundMessage) error
// Subscribe retrieves messages from the bus in an ordered matter.
Subscribe(ctx context.Context, subscriberName string, stream string, opts ...SubscribeOption) (*Subscription, error)
// Migrate ensures that dependencies (streams, topic, consumers, etc.) are up to date and ready to be used
Migrate(ctx context.Context) error
}
type OutboundMessage struct {
Id string
Subject string
Data []byte
}
type InboundMessage struct {
MessageCtx context.Context
Id string
Subject string
Data []byte
Ack func() error
Nak func(retryAfter time.Duration) error
deserializer serialization.Serializer
}
func (im *InboundMessage) Unmarshal(dst interface{}) error {
return im.deserializer.Deserialize(im.Data, dst)
}