Documentation ¶
Overview ¶
This package contains an example usage of redis-backed taskq. It includes two programs:
1. api that sends messages on the queue 2. worker that receives messages
They share common definitions for the queue `MainQueue` with a single task defined on it `CountTask`. api runs in a loop submitting messages to the queue, for each message it submits it increments a process-local counter. worker starts a consumer that executes the `CountTask` for each message receives - the task handler also implements a process local counter. If you run each program in a separate terminal with:
go run ./examples/redisexample/api/main.go go run ./examples/redisexample/worker/main.go
Then api will periodically print the messages sent to the terminal and worker will print the message received.
If you spawn further workers they will share consumption of the messages produced by api.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( QueueFactory = redisq.NewFactory() MainQueue = QueueFactory.RegisterQueue(&taskq.QueueOptions{ Name: "api-worker", Redis: Redis, }) CountTask = taskq.RegisterTask(&taskq.TaskOptions{ Name: "counter", Handler: func() error { IncrLocalCounter() time.Sleep(time.Millisecond) return nil }, }) )
var Redis = redis.NewClient(&redis.Options{
Addr: ":6379",
})
Functions ¶
func GetLocalCounter ¶
func GetLocalCounter() int32
func IncrLocalCounter ¶
func IncrLocalCounter()
func WaitSignal ¶
Types ¶
This section is empty.