Skip to content

A Go package for running an embedded NATS server.

License

Notifications You must be signed in to change notification settings

osapi-io/nats-server

release codecov go report card license build powered by conventional commits nats built with just gitHub commit activity

NATS Server

A Go package for running an embedded NATS server.

Usage

package main
import (
"log/slog"
"os"
"os/signal"
"syscall"
"time"
natsserver "github.com/nats-io/nats-server/v2/server"
"github.com/osapi-io/nats-server/pkg/server"
)
func main() {
debug := true
trace := debug
logger := slog.Default()
opts := &server.Options{
Options: &natsserver.Options{
JetStream: true,
Debug: debug,
Trace: trace,
StoreDir: ".nats/jetstream/",
NoSigs: true,
NoLog: false,
},
ReadyTimeout: 5 * time.Second,
}
s := server.New(logger, opts)
err := s.Start()
if err != nil {
logger.Error("failed to start server", "error", err)
os.Exit(1)
}
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt, syscall.SIGTERM)
<-quit
s.Stop()
}

See the examples section for additional use cases.

Documentation

See the generated documentation for details on available packages and functions.

Contributing

See the Development guide for prerequisites, setup, and conventions. See the Contributing guide before submitting a PR.

License

The MIT License.

About

A Go package for running an embedded NATS server.

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •