goqueue

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package goqueue adapts go-outbox envelopes to go-queue producers.

Example (Relay)
package main

import (
	"context"
	"fmt"
	"time"

	"github.com/faustbrian/go-outbox"
	"github.com/faustbrian/go-outbox/adapters/goqueue"
	"github.com/faustbrian/go-outbox/postgres"
	"github.com/faustbrian/go-outbox/relay"
	"github.com/faustbrian/go-queue/core"
	"github.com/faustbrian/go-queue/job"
)

func main() {
	queue := &exampleQueue{}
	publisher, _ := goqueue.New(queue)
	store := &exampleStore{}
	worker, _ := relay.New(store, publisher, relay.Config{Owner: "relay-a"})

	result, _ := worker.RunOnce(context.Background())

	fmt.Println(result.Claimed, queue.calls, store.delivered)
}

type exampleQueue struct {
	calls int
}

func (queue *exampleQueue) Queue(core.QueuedMessage, ...job.AllowOption) error {
	queue.calls++

	return nil
}

type exampleStore struct {
	claimed   bool
	delivered int
}

func (*exampleStore) Ping(context.Context) error { return nil }

func (*exampleStore) ExtendLease(context.Context, postgres.LeaseRef, time.Duration) (time.Time, error) {
	return time.Now(), nil
}

func (store *exampleStore) Claim(context.Context, postgres.ClaimRequest) ([]postgres.Claim, error) {
	if store.claimed {
		return nil, nil
	}
	store.claimed = true

	return []postgres.Claim{{
		Envelope: outbox.Envelope{
			ID: "evt-1", Topic: "orders.created", PayloadVersion: 1,
			AvailableAt: time.Unix(1, 0), CreatedAt: time.Unix(1, 0),
		},
		LeaseToken: "lease-token",
	}}, nil
}

func (store *exampleStore) MarkDelivered(context.Context, postgres.LeaseRef) error {
	store.delivered++

	return nil
}

func (*exampleStore) Retry(context.Context, postgres.LeaseRef, time.Time, error) error {
	return nil
}

func (*exampleStore) DeadLetter(context.Context, postgres.LeaseRef, error) error {
	return nil
}

func (*exampleStore) ReleaseLease(context.Context, postgres.LeaseRef) error { return nil }
Output:
1 1 1

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrQueueRequired = errors.New("outbox/goqueue: queue is required")

Functions

This section is empty.

Types

type Publisher

type Publisher struct {
	// contains filtered or unexported fields
}

Publisher enqueues canonical outbox envelopes through go-queue.

func New

func New(queue Queue) (*Publisher, error)

New creates a go-queue publisher adapter.

func (*Publisher) Publish

func (publisher *Publisher) Publish(ctx context.Context, envelope outbox.Envelope) error

Publish checks cancellation before entering go-queue, whose producer API is synchronous and does not accept a context. A nil result means go-queue accepted the message; it does not change the relay's at-least-once contract.

type Queue

type Queue interface {
	Queue(core.QueuedMessage, ...job.AllowOption) error
}

Queue is the narrow go-queue producer surface used by Publisher.

Jump to

Keyboard shortcuts

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