nats

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: MIT Imports: 5 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func With

func With(options nats.Options) nats.Option

With accepts a nats.Options structure which contains the whole configuration and returns a nats.Option which can be passed to the `NewStackExchange`'s second input variadic argument. Note that use this method only when you want to override the default options at once.

Types

type StackExchange

type StackExchange struct {

	// If you use the same nats server instance for multiple neffos apps,
	// set this to different values across your apps.
	SubjectPrefix string
	// contains filtered or unexported fields
}

StackExchange is a `neffos.StackExchange` for nats based on https://nats-io.github.io/docs/developer/tutorials/pubsub.html.

func NewStackExchange

func NewStackExchange(url string, options ...nats.Option) (*StackExchange, error)

NewStackExchange returns a new nats StackExchange. The required field is "url" which should be in the form of nats connection string, e.g. nats://username:pass@localhost:4222. Other option is to leave the url with localhost:4222 and pass authentication options such as `nats.UserInfo(username, pass)` or nats.UserCredentials("./userCredsFile") at the second variadic input argument.

Options can be used to register nats error and close handlers too.

Alternatively, use the `With(nats.Options)` function to customize the client through struct fields.

func (*StackExchange) Ask

func (exc *StackExchange) Ask(ctx context.Context, msg neffos.Message, token string) (response neffos.Message, err error)

Ask implements server Ask for nats. It blocks.

func (*StackExchange) NotifyAsk

func (exc *StackExchange) NotifyAsk(msg neffos.Message, token string) error

NotifyAsk notifies and unblocks a "msg" subscriber, called on a server connection's read when expects a result.

func (*StackExchange) OnConnect

func (exc *StackExchange) OnConnect(c *neffos.Conn) error

OnConnect prepares the connection nats subscriber and subscribes to itself for direct neffos messages. It's called automatically after the neffos server's OnConnect (if any) on incoming client connections.

func (*StackExchange) OnDisconnect

func (exc *StackExchange) OnDisconnect(c *neffos.Conn)

OnDisconnect terminates the connection's subscriber that created on the `OnConnect` method. It unsubscribes to all opened channels and closes the internal read messages channel. It's called automatically when a connection goes offline, manually by server or client or by network failure.

func (*StackExchange) Publish

func (exc *StackExchange) Publish(msgs []neffos.Message) bool

Publish publishes messages through nats. It's called automatically on neffos broadcasting.

func (*StackExchange) Subscribe

func (exc *StackExchange) Subscribe(c *neffos.Conn, namespace string)

Subscribe subscribes to a specific namespace, it's called automatically on neffos namespace connected.

func (*StackExchange) Unsubscribe

func (exc *StackExchange) Unsubscribe(c *neffos.Conn, namespace string)

Unsubscribe unsubscribes from a specific namespace, it's called automatically on neffos namespace disconnect.

Jump to

Keyboard shortcuts

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