GithubHelp home page GithubHelp logo

41north / natsutil.go Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 44 KB

A collection of utilities for working with https://nats.io/

License: Apache License 2.0

Go 88.57% Nix 11.43%
golang golang-library nats nats-client

natsutil.go's Introduction

natsutil.go

Build Coverage Status License

Status: EXPERIMENTAL

A collection of utilities for working with NATS.io.

Documentation

GoDoc

Full go doc style documentation for the project can be viewed online without installing this package by using the excellent GoDoc site here: http://godoc.org/github.com/41north/natsutil.go

You can also view the documentation locally once the package is installed with the godoc tool by running godoc -http=":6060" and pointing your browser to http://localhost:6060/pkg/github.com/41north/natsutil.go

Installation

$ go get -u github.com/41north/natsutil.go

Add this import line to the file you're working in:

import natsutil "github.com/41north/natsutil.go"

Quick Start

The following utilities will be of interest:

Subject Builder

A builder much like strings.Builder which helps with constructing valid subject names and ensures invalid characters are not used:

sb := natsutil.SubjectBuilder{}

// 'foo.bar.baz.*'
sb.Push("foo", "bar", "baz")
sb.Star()
subject := sb.String()

// 'foo.bar'
sb.Pop(2)
subject = sb.String()

// 'foo.bar.hello.>'
sb.Push("hello")
sb.Chevron()
subject = sb.String()

Generic Key Value Store

A generic interface for interacting with JetStream Key-Value stores can be created with the following:

type testPayload struct {
	Value int `json:""`
}

// create a nats connection
nc, err := nats.Connect(s.ClientURL(), opts...)
...

// get a JetStream context
js, err := nc.JetStream(nats.MaxWait(10 * time.Second))
...

// get a reference to the nats KV interface
kv, err := js.KeyValue("my-bucket")
...

// create a generic KeyValue interface that uses JSON encoding
encoder := builtin.JsonEncoder{}
kvT = natsutil.NewKeyValue[testPayload](kv, &codec)

// put a testPayload object
kvT.Put("foo", testPayload{1})

// get a testPayload object
get, err := kvT.Get("foo")

// create a generic Watcher
watcher, err := kvT.WatchAll()
...

License

Go-async is licensed under the Apache 2.0 License

Contact

If you want to get in touch drop us an email at [email protected]

natsutil.go's People

Contributors

brianmcgee avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.