Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import * as Hemera from './../../../packages/hemera'
import * as nats from 'nats'
type FileResult = {
do: string
isDone: boolean
}
const hemera = new Hemera(nats.connect('nats://127.0.0.1:4242'), {
logLevel: 'debug'
})
hemera.ready(async (err: Error) => {
// callback-style
hemera.ext('onAct', function(hemera, next) {
// some code
next()
})
hemera.ext('onActFinished', function(hemera, next) {
// some code
next()
})
hemera.ext('preHandler', function(hemera, request, reply, next) {
// some code
#!/usr/bin/env node
/* jslint node: true */
'use strict';
var nats = require ('nats').connect();
nats.on('error', function(/*exception*/) {
console.log('Can\'t connect to the nats-server [' + nats.options.url + '] is it running?');
});
var subject = process.argv[2];
if (!subject) {
console.log('Usage: node-sub ');
process.exit();
}
console.log('Listening on [' + subject + ']');
nats.subscribe(subject, function(msg) {
console.log('Received "' + msg + '"');
it('public getters', function(done) {
const nats = require('nats').connect(authUrl)
const hemera = new Hemera(nats)
expect(hemera.transport).to.be.exists()
expect(hemera.topics).to.be.exists()
expect(hemera.router).to.be.exists()
hemera.close(done)
})
})
it('Should log request and response logs', function(done) {
const nats = require('nats').connect(authUrl)
const stream = split(JSON.parse)
const hemera = new Hemera(nats, {
logLevel: 'debug',
logger: stream
})
const logs = []
stream.on('data', line => {
logs.push(line)
})
hemera.ready(() => {
hemera.add(
{
topic: 'math',
stan.on('connect', () => {
const connID = Buffer.from(stan.connId).toString('utf8');
const nc = NATS.connect({
encoding: "binary",
preserveBuffers: true,
port: PORT
});
nc.on('connect', () => {
nc.subscribe(stan.pubPrefix + ".hello", (msg) => {
const pm = proto.pb.PubMsg.deserializeBinary(new Uint8Array(msg));
const pm_cid = pm.getClientId();
clientID.should.be.equal(pm_cid);
const pm_connid = Buffer.from(pm.getConnId()).toString('utf8');
connID.should.be.equal(pm_connid);
nc.close();
done();
});
nc.flush(() => {
function setupNats(cb) {
cb = cb || function () {};
const servers = Piloted.serviceHosts('nats');
if (!servers || !servers.length) {
console.error('NATS not found');
return setTimeout(() => { setupNats(cb); }, 1000);
}
const natsServers = servers.map((server) => {
return `nats://${process.env.NATS_USER}:${process.env.NATS_PASSWORD}@${server.address}:4222`;
});
internals.nats = Nats.connect({ servers: natsServers });
internals.nats.on('error', (err) => {
console.log(err);
});
cb();
}
transporter: "NATS",
disableBalancer: true,
logLevel: "info"
});
broker.start().then(() => {
setInterval(() => {
broker.logger.info(chalk.yellow("Send..."));
//broker.emit("test.event", { ddata: "this is test data" }, ["group"]);
broker.broadcast("test.event", { data: "this is test data" }, ["group"]);
//broker.call("some.thing");
}, 2000);
});
const nats1 = NATS.connect({
url: "nats://localhost:4222",
name: "nodejs-subscriber-1"
});
nats1.subscribe("MOL.EVENTB.group.test.event", /*{ queue: "group" },*/ message => {
broker.logger.info(chalk.green.bold("nodejs-subscriber1: Test event received with payload:"), message);
});
const nats2 = NATS.connect({
url: "nats://localhost:4222",
name: "nodejs-subscriber-1"
});
nats2.subscribe("MOL.EVENTB.group.test.event", /*{ queue: "group" },*/ message => {
broker.logger.info(chalk.magenta.bold("nodejs-subscriber2: Test event received with payload:"), message);
});
'use strict'
const Hemera = require('./../../packages/hemera')
const nats = require('nats').connect()
const hemera = new Hemera(nats, {
logLevel: 'debug'
})
hemera.ready(() => {
hemera.ext('onAdd', addDefinition => {
hemera.log.info(addDefinition)
})
hemera.add(
{
topic: 'math',
cmd: 'add'
},
(req, cb) => {
cb(null, req.a + req.b)
broker.broadcast("test.event", { data: "this is test data" }, ["group"]);
//broker.call("some.thing");
}, 2000);
});
const nats1 = NATS.connect({
url: "nats://localhost:4222",
name: "nodejs-subscriber-1"
});
nats1.subscribe("MOL.EVENTB.group.test.event", /*{ queue: "group" },*/ message => {
broker.logger.info(chalk.green.bold("nodejs-subscriber1: Test event received with payload:"), message);
});
const nats2 = NATS.connect({
url: "nats://localhost:4222",
name: "nodejs-subscriber-1"
});
nats2.subscribe("MOL.EVENTB.group.test.event", /*{ queue: "group" },*/ message => {
broker.logger.info(chalk.magenta.bold("nodejs-subscriber2: Test event received with payload:"), message);
});
const config = require('./config');
const logger = require('./logger').child({ component: 'main' });
const Hemera = require('nats-hemera');
const nats = require('nats').connect({
url: config.get('nats.uri')
});
const Search = require('./search');
const search = Object.create(Search);
search.Search(config.get('elasticsearch.uri'), config.get('elasticsearch.index'));
const hemera = new Hemera(nats);
hemera.ready(function hemeraReady() {
hemera.add({
topic: 'build.query',
entity: 'log',
}, async function get(request) {
logger.info('Getting logs for build "%s" from "%d" to "%d"', request.target, request.from, request.to);