@@ -43,7 +43,8 @@ type DelayQueue struct {
4343 // for batch consume
4444 consumeBuffer chan string
4545
46- eventListener EventListener
46+ eventListener EventListener
47+ nackRedeliveryDelay time.Duration
4748}
4849
4950// NilErr represents redis nil
@@ -205,6 +206,13 @@ func (q *DelayQueue) WithDefaultRetryCount(count uint) *DelayQueue {
205206 return q
206207}
207208
209+ // WithNackRedeliveryDelay customizes the interval between redelivery and nack (callback returns false)
210+ // If consumption exceeded deadline, the message will be redelivered immediately
211+ func (q * DelayQueue ) WithNackRedeliveryDelay (d time.Duration ) * DelayQueue {
212+ q .nackRedeliveryDelay = d
213+ return q
214+ }
215+
208216func (q * DelayQueue ) genMsgKey (idStr string ) string {
209217 if q .useHashTag {
210218 return "{dp:" + q .name + "}" + ":msg:" + idStr
@@ -427,7 +435,7 @@ func (q *DelayQueue) nack(idStr string) error {
427435 atomic .AddInt32 (& q .fetchCount , - 1 )
428436 // update retry time as now, unack2Retry will move it to retry immediately
429437 err := q .redisCli .ZAdd (q .unAckKey , map [string ]float64 {
430- idStr : float64 (time .Now ().Unix ()),
438+ idStr : float64 (time .Now ().Add ( q . nackRedeliveryDelay ). Unix ()),
431439 })
432440 if err != nil {
433441 return fmt .Errorf ("negative ack failed: %v" , err )
0 commit comments