natsk

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 4 Imported by: 0

README

natsk - NATS Client Wrapper

📨 Custom Konsultin NATS client wrapper with auto-reconnect support.

Installation

go get github.com/konsultin/natsk

Quick Start

import "github.com/konsultin/natsk"

// Connect to NATS
client, err := natsk.New("nats://localhost:4222")
if err != nil {
    log.Fatal(err)
}
defer client.Close()

// Subscribe to a subject
client.Subscribe("orders.created", func(msg *nats.Msg) {
    fmt.Printf("Received: %s\n", string(msg.Data))
})

// Publish a message
client.Publish("orders.created", []byte(`{"id": "123"}`))

// Queue Subscribe (load-balanced)
client.QueueSubscribe("orders.created", "order-workers", func(msg *nats.Msg) {
    fmt.Printf("Worker received: %s\n", string(msg.Data))
})

Features

  • Auto-reconnect with configurable retry attempts
  • Queue subscriptions for load balancing
  • Graceful shutdown with drain support
  • Simple API - just New(), Subscribe(), Publish(), Close()

License

MIT License - see LICENSE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsConnectionError

func IsConnectionError(err error) bool

Types

type Client

type Client struct {
	Conn *nats.Conn
}

func New

func New(url string) (*Client, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) Publish

func (c *Client) Publish(subject string, data []byte) error

func (*Client) QueueSubscribe

func (c *Client) QueueSubscribe(subject, queue string, handler MsgHandler) (*nats.Subscription, error)

func (*Client) Subscribe

func (c *Client) Subscribe(subject string, handler MsgHandler) (*nats.Subscription, error)

type MsgHandler

type MsgHandler func(msg *nats.Msg)

Jump to

Keyboard shortcuts

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