redisexample

package module
v0.0.0-...-2956d04 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2022 License: BSD-2-Clause Imports: 9 Imported by: 0

README

taskq example using Redis backend

The example requires Redis Server running on the :6379.

First, start the consumer:

go run consumer/main.go

Then, start the producer:

go run producer/main.go

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

View Source
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
		},
	})
)
View Source
var Redis = redis.NewClient(&redis.Options{
	Addr: ":6379",
})

Functions

func GetLocalCounter

func GetLocalCounter() int32

func IncrLocalCounter

func IncrLocalCounter()

func LogStats

func LogStats()

func WaitSignal

func WaitSignal() os.Signal

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL