Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#!/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) {
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)