-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathworker_getmessages.go
30 lines (27 loc) · 1000 Bytes
/
worker_getmessages.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
package gomessagestore
import (
"context"
)
// GetMessages retrieves messages from the message store; Second process in the polling loop
func (sw *subscriptionWorker) GetMessages(ctx context.Context, position int64) ([]Message, error) {
opts := []GetOption{}
for _, conv := range sw.config.converters {
opts = append(opts, Converter(conv))
}
if !sw.config.stream { // for stream subscription
opts = append(opts, SincePosition(position))
if sw.config.commandCategory != "" { // for commands
opts = append(opts, CommandCategory(sw.config.commandCategory))
} else { // for events
opts = append(opts, Category(sw.config.category))
}
} else { // for category subscription
opts = append(opts, SinceVersion(position))
if sw.config.commandCategory != "" { // for commands
opts = append(opts, CommandStream(sw.config.commandCategory))
} else { // for events
opts = append(opts, EventStream(sw.config.category, sw.config.entityID))
}
}
return sw.ms.Get(ctx, opts...)
}