nats

package
v0.0.0-...-c1919a7 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	ChanSubscribe(subj string, ch chan *nats.Msg) (*nats.Subscription, error)
	Publish(subj string, data []byte) error
}

Client is the client used for NATS connections.

type Hub

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

Hub implements event.notifier and event.subscriber interfaces with a NATS pubsub implementation. The Hub needs to be started using Run.

func NewHub

func NewHub(cfg HubConfig) (*Hub, error)

NewHub returns a new hub based on a memory implementation.

func (*Hub) NotifyDiceRollCreated

func (h *Hub) NotifyDiceRollCreated(ctx context.Context, e model.EventDiceRollCreated) error

NotifyDiceRollCreated satisfies event.Notifier interface by pusblishing the event in a NATS pubsub stream, serialized in JSON.

func (*Hub) SubscribeDiceRollCreated

func (h *Hub) SubscribeDiceRollCreated(ctx context.Context, subscribeID, roomID string, handler func(context.Context, model.EventDiceRollCreated) error) error

SubscribeDiceRollCreated satisfies event.Subscriber interface.

func (*Hub) UnsubscribeDiceRollCreated

func (h *Hub) UnsubscribeDiceRollCreated(ctx context.Context, subscribeID, roomID string) error

UnsubscribeDiceRollCreated satisfies event.Subscriber interface.

type HubConfig

type HubConfig struct {
	// NATSClient is the client to connect to NATS server.
	NATSClient Client
	// Ctx is used to control the event loop, when the context is done,
	// the Hub will stop subscriptions and event handling and a new Hub is required.
	Ctx context.Context
	// Logger is the logger.
	Logger log.Logger
}

HubConfig is the hub configuration.

Jump to

Keyboard shortcuts

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