outbox

module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT

README

GO Outbox

A simple outbox for Go projects.

Install

Use go get.

$ go get github.com/assurrussa/outbox@v0.3.0

Then import the package into your own code:

import "github.com/assurrussa/outbox/outbox"

Usage

package main

import (
	"context"
	"time"

	"github.com/assurrussa/outbox/outbox"
	outboxlogger "github.com/assurrussa/outbox/outbox/logger"
	"github.com/assurrussa/outbox/shared/job"
)

type SendEmailJob struct {
	sharedjob.DefaultJob
}

func (*SendEmailJob) Name() string {
	return "send_email"
}

func (*SendEmailJob) Handle(ctx context.Context, payload string) error {
	_ = ctx
	_ = payload
	return nil
}

func main() {
	ctx := context.Background()

	svc, err := outbox.New(
		outbox.WithWorkers(1),
		outbox.WithReserveFor(time.Second),
		outbox.WithIdleTime(5*time.Minute),
		outbox.WithLogger(outboxlogger.WrapNamed(log, "any_custom_name_outbox_logger")),
		outbox.WithJobsRepo(jobsRepo),
		outbox.WithJobsStatRepo(jobsRepo),
		outbox.WithJobsFailedRepo(jobsFailedRepo),
		outbox.WithTransactor(txManager),
	)
	if err != nil {
		panic(err)
	}

	emailJob := &SendEmailJob{}
	svc.MustRegisterJob(emailJob)
	go func() {
		_ = svc.Run(ctx)
	}()

	_, _ = svc.Put(ctx, "send_email", `{"id":"1"}`, time.Now())
}

Storage drivers

  • Postgres storage: github.com/assurrussa/outbox/infrastructure/pgsql/storage
  • Picodata storage: github.com/assurrussa/outbox/infrastructure/picodata/storage

Migrations

Use embedded migrations for tools like goose:

package main

import (
	"context"

	"github.com/assurrussa/outbox/infrastructure/pgsql/migrator"
	"github.com/assurrussa/outbox/infrastructure/picodata/migrator"
)

func main() {
	ctx := context.Background()

	migrator.Run(
		ctx,
		db,
		lg,
		migrator.WithCommand(command),
		migrator.WithDirectory(dir),
		migrator.WithArgs(...),
	...,
)
}

License

This project is released under the MIT licence. See LICENSE for more details.

Directories

Path Synopsis
backends
pgsql module
picodata module
sqlite module
infrastructure
pgsql/storage/mocks
Package storagemocks is a generated GoMock package.
Package storagemocks is a generated GoMock package.
transport/mocks
Package transportmocks is a generated GoMock package.
Package transportmocks is a generated GoMock package.
jobs/payload
Package payload contains helper-packages common payload.
Package payload contains helper-packages common payload.
mocks
Package outboxmocks is a generated GoMock package.
Package outboxmocks is a generated GoMock package.
shared
job
tools
toolsmocks command

Jump to

Keyboard shortcuts

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