mirror of
https://github.com/HDT3213/delayqueue.git
synced 2025-10-05 07:06:53 +08:00
add monitor
This commit is contained in:
37
example/getstarted/main.go
Normal file
37
example/getstarted/main.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user