consumer

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

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

Consumer binds a durable JetStream pull consumer on the catalog events stream and applies volume.updated events to library entries. It runs as a background worker of the API process and is also startable standalone via cmd/consumer.

func New

func New(handler EventHandler) *Consumer

func (*Consumer) Start

func (c *Consumer) Start(ctx context.Context) error

Start connects to NATS, binds the durable consumer, and begins consuming in the background. Safe to pair with Stop even if Start returns an error.

func (*Consumer) Stop

func (c *Consumer) Stop(context.Context) error

Stop halts consumption and closes the connection. Idempotent.

type EventEnvelope

type EventEnvelope struct {
	EventID    string                 `json:"event_id"`
	OccurredAt string                 `json:"occurred_at"`
	Source     string                 `json:"source"`
	EntityType string                 `json:"entity_type"`
	EntityID   string                 `json:"entity_id"`
	Action     string                 `json:"action"`
	Revision   int                    `json:"revision"`
	Data       map[string]interface{} `json:"data"`
}

EventEnvelope is the platform event contract (see sweetrpg/platform docs/messaging-nats.md). Unknown fields are ignored so the envelope can grow without breaking this consumer.

type EventHandler

type EventHandler interface {
	HandleVolumeUpdated(ctx context.Context, event *EventEnvelope) error
}

type VolumeEventHandler

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

VolumeEventHandler applies volume.updated events: refresh the denormalized title on every referencing library entry, table volume, and wishlist entry, then drop the affected users' cached list and detail pages.

func NewVolumeEventHandler

func NewVolumeEventHandler(store persistence.CacheStore) *VolumeEventHandler

func (*VolumeEventHandler) HandleVolumeUpdated

func (h *VolumeEventHandler) HandleVolumeUpdated(ctx context.Context, event *EventEnvelope) error

Jump to

Keyboard shortcuts

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