add customizes msg ttl (#2)

add customizes msg ttl
This commit is contained in:
Yaya Liu
2022-09-22 10:40:45 +08:00
committed by GitHub
parent f93ae51a6d
commit 95a8a7139a
2 changed files with 12 additions and 2 deletions

View File

@@ -120,6 +120,14 @@ func WithRetryCount(count int) interface{} {
return retryCountOpt(count)
}
type msgTTLOpt time.Duration
// WithMsgTTL set ttl for a msg
// example: queue.SendDelayMsg(payload, duration, delayqueue.WithMsgTTL(Hour))
func WithMsgTTL(d time.Duration) interface{} {
return msgTTLOpt(d)
}
// SendScheduleMsg submits a message delivered at given time
func (q *DelayQueue) SendScheduleMsg(payload string, t time.Time, opts ...interface{}) error {
// parse options
@@ -128,6 +136,8 @@ func (q *DelayQueue) SendScheduleMsg(payload string, t time.Time, opts ...interf
switch o := opt.(type) {
case retryCountOpt:
retryCount = uint(o)
case msgTTLOpt:
q.msgTTL = time.Duration(o)
}
}
// generate id