nacl

package module
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT Imports: 6 Imported by: 0

README

nacl

Client helper for NATS/STAN

examples

connect to NATS

package main

import (
    "fmt"
    "github.com/jar3b/grawt"
    "github.com/jar3b/nacl"
    "github.com/kelseyhightower/envconfig"
)

func main() {
    // get params
    conf := config.NewConfig()

	// init waiter (github.com/jar3b/grawt)
	var waiter = grawt.NewWaiter()

	// init nats
	var subscriptions []*nacl.NatsSubscription
	if err := nacl.SetupNats(conf.Nats.Host, conf.Nats.Port, conf.Nats.User, conf.Nats.Pass,
		// handler called before app closed
        // we need to terminate sub's properly and sometimes doing another actions (finalizers)
        waiter.AddCloseHandler(func() {
			nacl.FinalizeNats(&subscriptions)
		}, false),
	); err != nil {
		waiter.Halt(fmt.Errorf("cannot connect to nats: %v", err))
	}
	defer nacl.NatsClient.Close()
	
    // here we add some subscriptions and wait (using blocking call)
    // ...
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	JsClient nats.JetStreamContext
)
View Source
var (
	NatsClient *nats.Conn
)

Functions

func AddOrUpdateConsumer added in v0.2.0

func AddOrUpdateConsumer(stream string, consumer string, cfg *nats.ConsumerConfig, allowDelete bool, opts ...nats.JSOpt) (*nats.ConsumerInfo, error)

func AddOrUpdateStream added in v0.2.0

func AddOrUpdateStream(cfg *nats.StreamConfig, opts ...nats.JSOpt) (*nats.StreamInfo, error)

func FinalizeJetStream added in v0.1.4

func FinalizeJetStream(subscriptions *[]*nats.Subscription) error

func FinalizeNats added in v0.0.2

func FinalizeNats(subscriptions *[]*nats.Subscription) error

func SetupJetStream added in v0.1.4

func SetupJetStream(host string, port int, credsFile string, appName string, closeHandler *grawt.CloseHandler, opts ...nats.JSOpt) error

func SetupNatsWithCreds added in v0.1.2

func SetupNatsWithCreds(
	natsURL string,
	credsFile string,
	appName string,
	closeHandler *grawt.CloseHandler,
	errorHandler nats.ErrHandler,
) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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