nats-proxy-bk
v1.2.1
Published
library to bridge websocket to nats-like usage for bahasakita projects
Downloads
30
Readme
nats-proxy-bk
library to bridge websocket to nats-like usage for bahasakita projects.
Installation
NPM
npm install nats-proxy-bk
CDN
Normal, development, and minified versions of the bundle can obtained via UNPKG.
<script type="text/javascript" src="https://unpkg.com/nats-proxy-bk/dist/nats-proxy-bk.js"></script>
Development (includes eval sourcemaps):
<script type="text/javascript" src="https://unpkg.com/nats-proxy-bk/dist/nats-proxy-bk.dev.js"></script>
Minified (for production use):
<script type="text/javascript" src="https://unpkg.com/nats-proxy-bk/dist/nats-proxy-bk.min.js"></script>
Basic Usage
var NATSProxy = require('nats-proxy-bk');
var nats = new NATSProxy('ws://localhost:4223');
// With options
const options = {
protocol: "nats",
timeout: 10
}
var nats = new NATSProxy('ws://localhost:4223', options);
// Simple Publisher
nats.publish('foo', 'Hello World!');
// Simple Subscriber
nats.subscribe('foo', function(msg) {
console.log('Received a message: ' + msg);
});
// Unsubscribing
nats.unsubscribe('foo');
// Request Streams
nats.request('request', 'Hello World!', function(response) {
console.log('Got a response in msg stream: ' + response);
});
// Close connection
nats.close();
Secure Websockets
Connections can be made to secure websockets by using the wss
protocol in the
url passed to NATSProxy
:
new NATSProxy('wss://localhost:4223');