forked from enerBit/redsumer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredsumer.go
43 lines (33 loc) · 854 Bytes
/
redsumer.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
package redsumer
import (
"context"
"github.com/enerBit/redsumer/pkg/client"
"github.com/enerBit/redsumer/pkg/consumer"
"github.com/redis/go-redis/v9"
)
type redConsumer struct {
args RedConsumerArgs
client *redis.Client
}
type RedConsumerArgs struct {
Group string
Stream string
ConsumerName string
RedisHost string
RedisPort int
Db int
}
func NewRedisConsumer(args RedConsumerArgs) (redConsumer, error) {
client, err := client.NewRedisClient(args.RedisHost, args.RedisPort, args.Db)
if err != nil {
return redConsumer{}, err
}
return redConsumer{
args: args,
client: client,
}, nil
}
func (c redConsumer) Consume(ctx context.Context) ([]redis.XMessage, error) {
messages, err := consumer.Consume(ctx, c.client, c.args.Group, c.args.ConsumerName, c.args.Stream)
return messages, err
}