wsmsg

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: Apache-2.0 Imports: 20 Imported by: 0

README

nats-wsmsg

nats based websocket message pubsub/queue server.

nats-wsmsg embeds gnatsd and provides high performance, portable portability, messaging capabilities.

Quick Start

Download latest release version appropriate for operating architecture.
Run.

$ ./nats-wsmsg -p 8080
example Pub/Sub

output1

example Pub/Queue

output2

see more example.

Build

Build requires Go version 1.11+ installed.

$ go version

Run make pkg to Build and package for linux, darwin.

$ git clone https://github.com/octu0/nats-wsmsg
$ make pkg

Help

NAME:
   nats-wsmsg

USAGE:
   nats-wsmsg [global options] command [command options] [arguments...]

VERSION:
   1.2.0

COMMANDS:
     help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   -i value, --ip value         server bind-ip (default: "0.0.0.0") [$WSMSG_BIND_IP]
   -p value, --port value       server bind-port (default: 8080) [$WSMSG_BIND_PORT]
   --max-payload value          msg max payload size (default: 1048576) [$WSMSG_MAX_PAYLOAD]
   --log-dir value              /path/to/log directory (default: "/tmp") [$WSMSG_LOG_DIR]
   --ws-max-message-size value  websocket max message size(byte) (default: 1048576) [$WSMSG_WS_MAX_MSG_SIZE]
   --procs value, -P value      attach cpu(s) (default: 8) [$WSMSG_PROCS]
   --debug, -d                  debug mode [$WSMSG_DEBUG]
   --verbose, -V                verbose. more message [$WSMSG_VERBOSE]
   --stdout-http-log            http-log outputs to standard out [$WSMSG_STDOUT_HTTP_LOG]
   --stdout-nats-log            nats-log outputs to standard out [$WSMSG_STDOUT_NATS_LOG]
   --help, -h                   show help
   --version, -v                print the version

Documentation

Index

Constants

View Source
const (
	DEFAULT_LOG_DIR             string = "/tmp"
	DEFAULT_BIND_IP             string = "0.0.0.0"
	DEFAULT_BIND_PORT           int    = 8080
	DEFAULT_MSG_MAX_PAYLOAD     int    = 1024 * 1024
	DEFAULT_PING_INTERVAL       int    = 1000
	DEFAULT_PING_OUT            int    = 5
	DEFAULT_WS_MAX_MESSAGE_SIZE int    = 1024 * 1024
)
View Source
const (
	AppName string = "nats-wsmsg"
	Version string = "1.2.0"
	UA      string = AppName + "/" + Version
)
View Source
const TAB string = "\t"

Variables

This section is empty.

Functions

func CreateNatsClient

func CreateNatsClient(ctx context.Context) (*nats.Conn, error)

func EncodeMessage

func EncodeMessage(nc *nats.Conn, msg *Message) ([]byte, error)

func NewNatsLogger

func NewNatsLogger(config Config) natsd.Logger

func PublishBinary

func PublishBinary(nc *nats.Conn, topic string, data []byte) error

func PublishText

func PublishText(nc *nats.Conn, topic string, data []byte) error

func WrapAccessLog

func WrapAccessLog(next http.Handler, logger HttpLogger) http.Handler

Types

type Config

type Config struct {
	DebugMode      bool
	VerboseMode    bool
	Procs          int
	LogDir         string
	NatsLogStdout  bool
	HttpLogStdout  bool
	BindIP         string
	BindPort       int
	MaxMessageSize int
}

type DefLogger

type DefLogger struct {
	// contains filtered or unexported fields
}

func (*DefLogger) Write

func (l *DefLogger) Write(host string, method string, uri string, status int, ua string)

type HttpController

type HttpController struct {
	// contains filtered or unexported fields
}

func NewHttpController

func NewHttpController(ctx context.Context) *HttpController

func (*HttpController) CheckStatus

func (c *HttpController) CheckStatus(res http.ResponseWriter, req *http.Request)

func (*HttpController) HttpHandler

func (c *HttpController) HttpHandler() http.Handler

func (*HttpController) TopicPublish

func (c *HttpController) TopicPublish(res http.ResponseWriter, req *http.Request)

func (*HttpController) TopicSubscribe

func (c *HttpController) TopicSubscribe(res http.ResponseWriter, req *http.Request)

func (*HttpController) TopicSubscribeWithQueue

func (c *HttpController) TopicSubscribeWithQueue(res http.ResponseWriter, req *http.Request)

func (*HttpController) Version

func (c *HttpController) Version(res http.ResponseWriter, req *http.Request)

type HttpLogger

type HttpLogger interface {
	Write(host string, method string, uri string, status int, ua string)
}

func NewHttpLogger

func NewHttpLogger(config Config) HttpLogger

type HttpServer

type HttpServer struct {
	Server     *http.Server
	Controller *HttpController
	// contains filtered or unexported fields
}

func NewHttpServer

func NewHttpServer(ctx context.Context) *HttpServer

func (*HttpServer) Start

func (s *HttpServer) Start(sctx context.Context) error

func (*HttpServer) Stop

func (s *HttpServer) Stop(sctx context.Context) error

type Message

type Message struct {
	MsgType int
	Data    []byte
}

func DecodeMessage

func DecodeMessage(nc *nats.Conn, data []byte) (*Message, error)

type MultiLogger

type MultiLogger struct {
	// contains filtered or unexported fields
}

func (*MultiLogger) Write

func (m *MultiLogger) Write(p []byte) (int, error)

type NatsLogger

type NatsLogger struct {
	// contains filtered or unexported fields
}

func (*NatsLogger) Debugf

func (n *NatsLogger) Debugf(format string, v ...interface{})

func (*NatsLogger) Errorf

func (n *NatsLogger) Errorf(format string, v ...interface{})

func (*NatsLogger) Fatalf

func (n *NatsLogger) Fatalf(format string, v ...interface{})

func (*NatsLogger) Noticef

func (n *NatsLogger) Noticef(format string, v ...interface{})

func (*NatsLogger) Tracef

func (n *NatsLogger) Tracef(format string, v ...interface{})

func (*NatsLogger) Warnf

func (n *NatsLogger) Warnf(format string, v ...interface{})

type SendQueue

type SendQueue chan *Message

type SubQueue

type SubQueue chan *nats.Msg

type WebsocketHandler

type WebsocketHandler struct {
	// contains filtered or unexported fields
}

func CreateWebsocketHandler

func CreateWebsocketHandler(ctx context.Context, res http.ResponseWriter, req *http.Request) (*WebsocketHandler, error)

func (*WebsocketHandler) Close

func (ws *WebsocketHandler) Close() error

func (*WebsocketHandler) RunSubscribe

func (ws *WebsocketHandler) RunSubscribe(topic string) error

func (*WebsocketHandler) RunSubscribeWithGroup

func (ws *WebsocketHandler) RunSubscribeWithGroup(topic, group string) error

type WrapWriter

type WrapWriter struct {
	Writer     http.ResponseWriter
	LastStatus int
}

func (*WrapWriter) Header

func (w *WrapWriter) Header() http.Header

func (*WrapWriter) Hijack

func (w *WrapWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)

allow hijack

func (*WrapWriter) Write

func (w *WrapWriter) Write(b []byte) (int, error)

func (*WrapWriter) WriteHeader

func (w *WrapWriter) WriteHeader(status int)

Directories

Path Synopsis
example
queue command
subscribe command

Jump to

Keyboard shortcuts

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