-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsubscription_worker.go
More file actions
32 lines (27 loc) · 1.09 KB
/
subscription_worker.go
File metadata and controls
32 lines (27 loc) · 1.09 KB
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
package gomessagestore
import (
"context"
)
//go:generate bash -c "${GOPATH}/bin/mockgen github.com/blackhatbrigade/gomessagestore SubscriptionWorker > mocks/subscriptionworker.go"
// SubscriptionWorker handles the processes for retrieving and processing messages from the message store and updating positions
type SubscriptionWorker interface {
GetMessages(ctx context.Context, position int64) ([]Message, error)
ProcessMessages(ctx context.Context, msgs []Message) (messagesHandled int, positionOfLastHandled int64, err error)
GetPosition(ctx context.Context) (int64, error)
SetPosition(ctx context.Context, position int64) error
}
type subscriptionWorker struct {
config *SubscriberConfig
ms MessageStore
handlers []MessageHandler
subscriberID string
}
// CreateWorker returns a new subscriptionWorker
func CreateWorker(ms MessageStore, subscriberID string, handlers []MessageHandler, config *SubscriberConfig) (SubscriptionWorker, error) {
return &subscriptionWorker{
ms: ms,
handlers: handlers,
config: config,
subscriberID: subscriberID,
}, nil
}