bus

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind

func Bind[T comparable](input Message) (T, error)

Types

type Consumer

type Consumer func(ctx context.Context, message Message) error

type FormSubmittedEvent

type FormSubmittedEvent struct {
	RequestType string
	Message     string
	UserID      int64
}

type Handler

type Handler interface {
	Consumers() map[Topic][]Consumer
}

type Message

type Message []byte

type PaymentStatusUpdateEvent

type PaymentStatusUpdateEvent struct {
	MerchantID int64
	PaymentID  int64
}

type PubSub

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

PubSub simple pub-sub implementation. Works locally using in-memory store. No persistence, no semaphores. Should do the job until we switch to a real bus (e.g. Kafka).

func NewPubSub

func NewPubSub(ctx context.Context, async bool, logger *zerolog.Logger) *PubSub

func (*PubSub) Publish

func (p *PubSub) Publish(topic Topic, message any) error

func (*PubSub) RegisterHandler

func (p *PubSub) RegisterHandler(h Handler) error

func (*PubSub) Shutdown

func (p *PubSub) Shutdown() error

func (*PubSub) Subscribe

func (p *PubSub) Subscribe(topic Topic, fn Consumer) error

type Publisher

type Publisher interface {
	Publish(topic Topic, message any) error
}

type Topic

type Topic string
const (
	TopicPaymentStatusUpdate Topic = "payment.status"
	TopicWithdrawals         Topic = "withdrawal"
	TopicFormSubmissions     Topic = "form.submitted"
	TopicUserRegistered      Topic = "user.registered"
)

type UserRegisteredEvent

type UserRegisteredEvent struct {
	UserID int64
}

type WithdrawalCreatedEvent

type WithdrawalCreatedEvent struct {
	MerchantID int64
	PaymentID  int64
}

Jump to

Keyboard shortcuts

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