add monitor

This commit is contained in:
finley
2024-02-16 18:55:39 +08:00
parent f3ca206c87
commit 2e259ed5f3
12 changed files with 832 additions and 24 deletions

View File

@@ -0,0 +1,37 @@
package main
import (
"github.com/hdt3213/delayqueue"
"github.com/redis/go-redis/v9"
"strconv"
"time"
)
func main() {
redisCli := redis.NewClient(&redis.Options{
Addr: "127.0.0.1:6379",
})
queue := delayqueue.NewQueue("example", redisCli, func(payload string) bool {
// callback returns true to confirm successful consumption.
// If callback returns false or not return within maxConsumeDuration, DelayQueue will re-deliver this message
println(payload)
return true
}).WithConcurrent(4)
// send delay message
for i := 0; i < 10; i++ {
err := queue.SendDelayMsg(strconv.Itoa(i), time.Second, delayqueue.WithRetryCount(3))
if err != nil {
panic(err)
}
}
// send schedule message
for i := 0; i < 10; i++ {
err := queue.SendScheduleMsg(strconv.Itoa(i), time.Now().Add(time.Second))
if err != nil {
panic(err)
}
}
// start consume
done := queue.StartConsume()
<-done
}