webhookqueue

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package webhookqueue adapts bounded delivery requests to queue messages.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInvalidConfig = errors.New("webhook/queue: invalid configuration")

Functions

func Handle

func Handle(
	ctx context.Context,
	deliverer *webhook.Deliverer,
	encoded []byte,
	maxMessageBytes int,
) (webhook.DeliveryResult, error)

Handle strictly decodes one message and performs one HTTP attempt. The surrounding queue owns any retry schedule and settlement behavior.

Types

type Adapter

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

Adapter enqueues versioned delivery requests.

func New

func New(config Config) (*Adapter, error)

New validates the queue and message bound.

func (*Adapter) Enqueue

func (a *Adapter) Enqueue(ctx context.Context, delivery webhook.DeliveryRequest) error

Enqueue checks cancellation, encodes a bounded request, and synchronously hands it to queue. Acceptance is not an exactly-once guarantee.

Example
package main

import (
	"context"
	"fmt"
	"net/url"

	"github.com/faustbrian/go-queue/core"
	"github.com/faustbrian/go-queue/job"
	webhook "github.com/faustbrian/go-webhook"
	"github.com/faustbrian/go-webhook/adapters/queue"
)

func main() {
	queue := &fixtureQueue{}
	adapter, _ := webhookqueue.New(webhookqueue.Config{Queue: queue, MaxMessageBytes: 4096})
	endpoint, _ := url.Parse("https://receiver.example/hooks")
	_ = adapter.Enqueue(context.Background(), webhook.DeliveryRequest{
		Endpoint: endpoint, Body: []byte(`{"order":123}`),
		EventID: "event-123", IdempotencyKey: "event-123",
	})
	delivery, _ := webhook.UnmarshalDeliveryRequest(queue.message.Bytes(), 4096)
	fmt.Println(delivery.EventID, string(delivery.Body))
}

type fixtureQueue struct {
	message core.QueuedMessage
}

func (q *fixtureQueue) Queue(message core.QueuedMessage, _ ...job.AllowOption) error {
	q.message = message
	return nil
}
Output:
event-123 {"order":123}

type Config

type Config struct {
	Queue           Queue
	MaxMessageBytes int
	JobOptions      []job.AllowOption
}

Config bounds messages and optionally assigns queue-level retry policy. Delivery handling always performs one HTTP attempt, preventing nested retry multiplication.

type Queue

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

Queue is the narrow synchronous producer surface implemented by queue.

Jump to

Keyboard shortcuts

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