How to use the node-nats-streaming.connect function in node-nats-streaming

To help you get started, we’ve selected a few node-nats-streaming examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nats-io / stan.js / examples / readme_samples / basic.js View on Github external
#!/usr/bin/env node

"use-strict";

var stan = require('node-nats-streaming').connect('test-cluster', 'test');

stan.on('connect', function () {

  // Simple Publisher (all publishes are async in the node version of the client)
  stan.publish('foo', 'Hello node-nats-streaming!', function(err, guid){
    if(err) {
      console.log('publish failed: ' + err);
    } else {
      console.log('published message with guid: ' + guid);
    }
  });

  // Subscriber can specify how many existing messages to get.
  var opts = stan.subscriptionOptions().setStartWithLastReceived();
  var subscription = stan.subscribe('foo', opts);
  subscription.on('message', function (msg) {
github hemerajs / hemera / packages / hemera-nats-streaming / index.js View on Github external
function hemeraNatsStreaming(hemera, opts, done) {
  const topic = 'nats-streaming'
  const Joi = hemera.joi
  const DuplicateSubscriberError = hemera.createError('DuplicateSubscriber')
  const ParsingError = hemera.createError('ParsingError')
  const NotAvailableError = hemera.createError('NotAvailable')
  const stan = Nats.connect(opts.clusterId, opts.clientId, opts.opts)
  const subList = {}

  hemera.decorate('natsStreamingErrors', {
    DuplicateSubscriberError,
    ParsingError,
    NotAvailableError
  })

  hemera.ext('onClose', (ctx, done) => {
    hemera.log.debug('Stan closing ...')
    stan.close()
    done()
  })

  stan.on('error', err => {
    hemera.log.error(err)

node-nats-streaming

Node.js client for NATS Streaming, a lightweight, high-performance cloud native messaging system

Apache-2.0
Latest version published 5 years ago

Package Health Score

59 / 100
Full package analysis

Popular node-nats-streaming functions