pubsub

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionType

type ActionType string
const (
	ActionTypeCreate ActionType = "create"
	ActionTypeUpdate ActionType = "update"
	ActionTypeDelete ActionType = "delete"
)

type Client

type Client interface {
	PublishSubscriber
	// WithTopic creates a new Client with the given topic.
	SetTopic(topic string) Client
	// Close closes the connection.
	Close(context.Context) error
}

func NewNatsClient

func NewNatsClient(connectStr string, defaultTopic string) (Client, error)

type DefaultEvent

type DefaultEvent struct {
	// ResourceID is the ResourceID of the object that was created, updated or deleted.
	ResourceID uuid.UUID
	// ActionType is the type of the event.
	ActionType ActionType
	// AdditionalData is additional data that can be used to pass additional information.
	AdditionalData map[string]any
}

func (*DefaultEvent) Action

func (d *DefaultEvent) Action() ActionType

Action is the type of the event.

func (*DefaultEvent) ID

func (d *DefaultEvent) ID() uuid.UUID

ID is the ID of the object that was created, updated or deleted.

type Event

type Event interface {
	// ID is the ID of the object that was created, updated or deleted.
	ID() uuid.UUID
	// Action is the type of the event.
	Action() ActionType
}

type PublishSubscriber

type PublishSubscriber interface {
	Publisher
	Subscriber
}

type Publisher

type Publisher interface {
	// Publish publishes a message.
	Publish(message Event) error
}

type SubscribeDater

type SubscribeDater interface {
	// Ack acknowledges the message.
	Ack()
	// Data returns the message data.
	Data() []byte
}

type Subscriber

type Subscriber interface {
	// Subscribe returns a channel that will receive messages.
	// This function blocks until the subscription is ready (unbuffered channel).
	Subscribe() (<-chan SubscribeDater, error)
}

Jump to

Keyboard shortcuts

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