natspkg

package
v0.0.5 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEmbeddedServer

func NewEmbeddedServer(ctx context.Context) (string, error)

NewEmbeddedServer start an embedded NATS server for stage/testing

Types

type Client

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

Client holds the connection to NATS

func NewClient

func NewClient(ctx context.Context, config Config) (*Client, error)

NewClient returns a new client with the connection

type Config

type Config struct {
	URL            string
	EmbeddedServer bool
}

Config holds nats config

type INats

type INats interface {
	Publish(ctx context.Context, publishRequest PublishRequest) error
	Subscribe(ctx context.Context, channel string) (broker.ISubscription, error)
	UnSubscribe(ctx context.Context, s broker.ISubscription) error
}

INats is an interface over nats pubsub and jetstream

type JetStream

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

JetStream ...

func NewJetStream

func NewJetStream(ctx context.Context, c *Client) (*JetStream, error)

NewJetStream returns nats NewJetStream

func (*JetStream) CreateKeyValue

func (j *JetStream) CreateKeyValue(ctx context.Context, bucket string) (*KV, error)

CreateKeyValue for NATS

func (*JetStream) Publish

func (j *JetStream) Publish(ctx context.Context, request PublishRequest) error

Publish data to the subject

func (*JetStream) Subscribe

func (j *JetStream) Subscribe(ctx context.Context, channel string) (broker.ISubscription, error)

Subscribe to jetstream topic

func (*JetStream) UnSubscribe

func (j *JetStream) UnSubscribe(ctx context.Context, s broker.ISubscription) error

UnSubscribe from jetstream topic

type JetStreamSubscription

type JetStreamSubscription struct {
	broker.BaseSubscription
	JetStream
	// contains filtered or unexported fields
}

JetStreamSubscription ...

type KV

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

KV struct for NATS

func (*KV) Delete

func (kv *KV) Delete(ctx context.Context, key string) error

Delete a key

func (*KV) Get

func (kv *KV) Get(ctx context.Context, key string) ([]byte, error)

Get value for a key

func (*KV) Put

func (kv *KV) Put(ctx context.Context, key string, value []byte) error

Put a key with value

type PubSub

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

PubSub provides nats pubsub implementation

func NewPubSub

func NewPubSub(c *Client) *PubSub

NewPubSub returns nats PubSub

func (PubSub) Publish

func (s PubSub) Publish(ctx context.Context, request PublishRequest) error

Publish data to the subject

func (PubSub) Subscribe

func (s PubSub) Subscribe(ctx context.Context, subject string) (broker.ISubscription, error)

Subscribe to a subject

func (PubSub) UnSubscribe

func (s PubSub) UnSubscribe(ctx context.Context, subscription broker.ISubscription) error

UnSubscribe a subscriber

type PubSubSubscription

type PubSubSubscription struct {
	broker.BaseSubscription
	// contains filtered or unexported fields
}

PubSubSubscription ...

type PublishRequest

type PublishRequest struct {
	Channel string
	Data    []byte
}

PublishRequest is the publishRequest

Jump to

Keyboard shortcuts

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