natsjs

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArgoUnmarshalEvent

func ArgoUnmarshalEvent(dest interface{}, str string) (err error)

func Close

func Close()

func Connect

func Connect()

Connect establishes a connection to the NATS server.

USAGE:

import "api/lib/stream"

stream.New().

InitStream("default").
NewMessage().
SetSubject("notifications.email", params.Kind, params.Category).
SetData(map[string]int{"pending_notifications_id": row.ID}).
Publish()

func SetReconnect

func SetReconnect(r bool)

func SetTimeout

func SetTimeout(t time.Duration)

func UnmarshalEvent

func UnmarshalEvent(dest interface{}, str string) (err error)

Types

type ArgoEvent

type ArgoEvent struct {
	Context ArgoEventContext `json:"context"`
	Data    string           `json:"data"`
}

Event represents an event received from an argo event source

func ArgoEventFromString

func ArgoEventFromString(str string) (ArgoEvent, error)

func (ArgoEvent) JSONBody

func (e ArgoEvent) JSONBody() (string, error)

type ArgoEventContext

type ArgoEventContext struct {
	ID              string `json:"id"`
	Source          string `json:"source"`
	SpecVersion     string `json:"specversion"`
	Type            string `json:"type"`
	DataContentType string `json:"datacontenttype"`
	Subject         string `json:"subject"`
	Time            string `json:"time"`
}

EventContext represents the context of an event

type ArgoEventData

type ArgoEventData struct {
	Subject string      `json:"subject"`
	Body    interface{} `json:"body"`
}

type Client

type Client struct{}

func New

func New() *Client

func (*Client) InitStream

func (c *Client) InitStream(streamName string) *Client

func (*Client) NewMessage

func (c *Client) NewMessage() *Message

type Consumer

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

func NewConsumer

func NewConsumer(name, stream, subject string) *Consumer

func (Consumer) Consume

func (c Consumer) Consume(callback func(jetstream.Msg) error) (stop func(), err error)

type Message

type Message struct {
	Subject string
	Data    []byte
}

func (*Message) Publish

func (m *Message) Publish() error

func (*Message) SetData

func (m *Message) SetData(raw interface{}) *Message

func (*Message) SetSubject

func (m *Message) SetSubject(streamName, prefix string, suffix ...string) *Message

SetSubject sets the subject of the message. The subject is used to route the message to the correct stream.

even though stream name is not required to relate a message to a stream, it forces our naming convention and makes it easier to find the stream that the message belongs to

Jump to

Keyboard shortcuts

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