-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathpublisher.go
44 lines (36 loc) · 1.2 KB
/
publisher.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
package delayqueue
import (
"log"
"time"
"github.com/redis/go-redis/v9"
)
// Publisher only publishes messages to delayqueue, it is a encapsulation of delayqueue
type Publisher struct {
inner *DelayQueue
}
// NewPublisher0 creates a new Publisher by a RedisCli instance
func NewPublisher0(name string, cli RedisCli, opts ...interface{}) *Publisher {
return &Publisher{
inner: NewQueue0(name, cli, opts...),
}
}
// NewPublisher creates a new Publisher by a *redis.Client
func NewPublisher(name string, cli *redis.Client, opts ...interface{}) *Publisher {
rc := &redisV9Wrapper{
inner: cli,
}
return NewPublisher0(name, rc, opts...)
}
// WithLogger customizes logger for queue
func (p *Publisher) WithLogger(logger *log.Logger) *Publisher {
p.inner.logger = logger
return p
}
// SendScheduleMsg submits a message delivered at given time
func (p *Publisher) SendScheduleMsg(payload string, t time.Time, opts ...interface{}) error {
return p.inner.SendScheduleMsg(payload, t, opts...)
}
// SendDelayMsg submits a message delivered after given duration
func (p *Publisher) SendDelayMsg(payload string, duration time.Duration, opts ...interface{}) error {
return p.inner.SendDelayMsg(payload, duration, opts...)
}