Giter Site home page Giter Site logo

nats-websocket-gw's Introduction

NATS <-> websocket gateway

A websocket gateway for NATS, usable as a backend for elm-nats and websocket-nats.

Features:

  • TLS support
  • Each NATS command is sent as a separate websocket message
  • Provides a hook to change the CONNECT phase, allowing the http server to handle the connection itself (for example based on a cookie of the http request)
  • Easily embeddable in a bigger http server
  • Supports both text (default) and binary (by adding '?mode=binary' to the url) messages

Basic usage

Fetch the source:

go get -u github.com/orus-io/nats-websocket-gw

Install and run the default binary

go install github.com/orus-io/nats-websocket-gw/cmd/nats-websocket-gw
nats-websocket-gw --no-origin-check

and/or integrate it in your http server:

package main

import (
	"net/http"

	"github.com/orus-io/nats-websocket-gw"
)

func main() {
	gateway := gw.NewGateway(gw.Settings{
		NatsAddr: "localhost:4222",
	})
	http.HandleFunc("/nats", gateway.Handler)
	http.ListenAndServe("0.0.0.0:8910", nil)
}

How does it differ from other nats-websocket servers ?

  • Rest to NATS Proxy provides a websocket based implementation. The approach is pretty different though, as the websockets do not transport the whole NATS protocol, but only the data of the messages (websockets are opened for each subscribed subject).

  • ws-tcp-relay, which the proposed backend for websocket-nats is a generic ws-tcp gateway. As such, it:

    • does not allow for TLS connections to NATS because the TLS negociation cannot be done immediately (the NATS protocol has a clear text 'INFO' exchange before TLS handshake)
    • send websocket messages that may contain several NATS commands.

nats-websocket-gw's People

Contributors

cdevienne avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

nats-websocket-gw's Issues

Subscribe problems (trought websocket-nats)

Hi, thank you for this library at first! I tried it with js ("websocket-nats") on the front side. Publish functional works is ok, but subscribe does not for me. It looks like proxy sends data from "front-end" to "NATS server" only. Do you have some ideas or examples?

Using Nats authentification

Hi,

I upgraded my Nats server with authentification system.
But that doesn't work with nats-websocket-gw.

Instead of providing a standard nats path: "localhost:1234"
I added the user and password info: "[john:doe@localhost]:21400"
(braquets are added following this rule: https://socketloop.com/tutorials/golang-dial-tcp-too-many-colons-in-address)

But this bring also in issue with dial tcp:
[ERROR] dial tcp: lookup john:doe@localhost: no such host

Is there another way to pass credentials information for Nats?

Thanks

Publish binary data

Hi,

I try to transfert binary buffer to a Nats client using our gateway and websocket-nats.
But binary data don't seems to be handled well.
I get some "EOF" messages which seems to be related to a string format.

Could you tell me how to configure the connection beween websocket-nats and your gateway in binary please?

Thanks.
Michael

certificates

Would it be possible to expose -port, -cert, -key as cli options so we could also use secure websockets?

//cc @cdevienne

Thanks ;)

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.