taskq

Golang asynchronous task queue with Redis, SQS, and IronMQ backends

Getting started

Familiar API

Using taskq, you can turn any Go function into an asynchronous task.

Multiple backends

taskq supports Redis, Simple Queue Service (SQS), IronMQ, and in-memory backends.

OpenTelemetry

Monitor performance and errors using OpenTelemetry instrumentation.

Producer

import (
    "github.com/vmihailenco/taskq/v3"
    "github.com/vmihailenco/taskq/v3/redisq"
)

// Create a queue factory.
var QueueFactory = redisq.NewFactory()

// Create a queue.
var MainQueue = QueueFactory.RegisterQueue(&taskq.QueueOptions{
    Name:  "api-worker",
    Redis: Redis, // go-redis client
})

// Register a task.
var CountTask = taskq.RegisterTask(&taskq.TaskOptions{
    Name: "counter",
    Handler: func() error {
        IncrLocalCounter()
        return nil
    },
})

ctx := context.Background()

// And start producing.
for {
	// Call the task without any args.
	err := MainQueue.Add(CountTask.WithArgs(ctx))
	if err != nil {
		panic(err)
	}
	time.Sleep(time.Second)
}

Consumer

// Start consuming the queue.
if err := MainQueue.Consumer().Start(context.Background()); err != nil {
    log.Fatal(err)
}