Skip to content

Golang asynchronous task/job queue with Redis, SQS, IronMQ, and in-memory backends

License

Notifications You must be signed in to change notification settings

vmihailenco/taskq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2956d04 · Dec 6, 2022
Oct 28, 2021
Oct 11, 2021
Aug 24, 2022
Aug 24, 2022
Oct 11, 2021
Oct 5, 2021
Nov 21, 2021
Oct 12, 2022
Oct 11, 2021
Jul 4, 2019
Sep 3, 2021
Aug 24, 2022
Mar 18, 2017
Apr 25, 2022
Apr 25, 2022
Sep 3, 2021
Sep 3, 2021
Jan 11, 2020
Oct 11, 2021
Oct 11, 2021
Jan 30, 2020
Oct 28, 2021
Jun 1, 2019
Jan 11, 2020
Mar 11, 2020
Apr 25, 2022
Apr 25, 2022
Apr 3, 2020
Sep 3, 2021
Jun 21, 2022
Aug 24, 2022
Mar 26, 2022
Oct 21, 2021
Aug 19, 2020
Nov 21, 2021
Oct 11, 2021
Oct 11, 2021
Aug 11, 2019
Nov 21, 2021
Aug 24, 2022

Repository files navigation

Golang asynchronous task/job queue with Redis, SQS, IronMQ, and in-memory backends

build workflow PkgGoDev Documentation Chat

taskq is brought to you by ⭐ uptrace/uptrace. Uptrace is an open source and blazingly fast distributed tracing tool powered by OpenTelemetry and ClickHouse. Give it a star as well!

Features

  • Redis, SQS, IronMQ, and in-memory backends.
  • Automatically scaling number of goroutines used to fetch (fetcher) and process messages (worker).
  • Global rate limiting.
  • Global limit of workers.
  • Call once - deduplicating messages with same name.
  • Automatic retries with exponential backoffs.
  • Automatic pausing when all messages in queue fail.
  • Fallback handler for processing failed messages.
  • Message batching. It is used in SQS and IronMQ backends to add/delete messages in batches.
  • Automatic message compression using snappy / s2.

Resources:

Getting started

To get started, see Golang Task Queue documentation.

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.Start(context.Background()); err != nil {
    log.Fatal(err)
}

See also

Contributors

Thanks to all the people who already contributed!