Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*/
var requestChannel = (channelName) => '@request:' + channelName + '@'
/**
*
* @param channelName
* @param query
* @returns {string}
*/
var responseChannel = (channelName, query) => '@response:' + channelName + ':' + query + '@'
/**
*
* @param cb
*/
const opt = { credentials: require('amqplib').credentials.plain('test', 'test') };
var connectRabbitMq = (cb) => amqp.connect('amqp://' + settings.RABBITMQHOST,
opt,
(err, conn) => {
if (err) console.log(err)
else cb(conn)
});
/**
*
* @returns {*}
*/
var defaultTimeout = (conn) => setTimeout(() => conn.close(), 500)
/**
*
* @param queueName
private connect(cb: () => void) {
let opt = {
credentials: require("amqplib").credentials.plain(
this.brokerUser,
this.brokerPass
)
};
let url = this.ampqUrl + "?heartbeat=60";
logger.debug("Connecting to " + url);
var that = this;
try {
this.connectToBroker(url, opt, async function(err, conn: Connection) {
if (err) {
logger.error("[AMQP] Error:" + err.message);
logger.info("Waiting to reconnect");
let timeout: number;
if (that.reconnectAfterMilliSecs)
timeout = that.reconnectAfterMilliSecs;
else timeout = 6000;
private static doConnection(
cb: () => void,
user: string,
pass: string,
ampqUrl: string,
myConn: AmqpConnectionDetails,
brokerExchange: string
) {
let opt = {
credentials: require("amqplib").credentials.plain(user, pass)
};
let url = ampqUrl + "?heartbeat=60";
logger.debug("Connecting to " + url);
try {
amqp.connect(url, opt, async function(err, conn: Connection) {
if (err) {
logger.error("[AMQP]:" + err.message);
//return;
logger.info("Waiting to reconnect");
await AmqpClient.sleep(6000);
logger.info("reconnecting. Call count:" + AmqpClient.retryCounter++);
//TODO: recursion, watch out for stack overflow
AmqpClient.doConnection(
cb,
user,
pass,
private connect(cb: () => void) {
let opt = {
credentials: require("amqplib").credentials.plain(
this.brokerUser,
this.brokerPass
)
};
let url = " amqp://" + this.ampqUrl + "?heartbeat=60";
logger.debug("Connecting to " + url);
var that = this;
try {
this.connectToBroker(url, opt, async function(err, conn: Connection) {
if (err) {
logger.error("[AMQP] Error:" + err.message);
logger.info("Waiting to reconnect");
let timeout: number;
if (that.reconnectAfterMilliSecs)
timeout = that.reconnectAfterMilliSecs;
else timeout = 6000;
const amqp = require('amqplib/callback_api')
const log = require('loglevel')
const Parity = require('../common/parity')
const Promise = require('bluebird')
const errorHandler = require('../common/errorHandlers')
const settings = require('../common/settings')
const db = require('../db')
log.enableAll()
const parity = Parity(db, log)
const opt = { credentials: require('amqplib').credentials.plain(settings.RABBITMQ.user,
settings.RABBITMQ.password) }
/**
* Function responsible for caching all variables' values in a given range [from, upTo]
*
* Consists of 4 steps
* Step 1 - parity,getHistory call (getting events in a given range)
* Step 2 - caching blocks' timestamps
* Step 3 - caching transactions
* Step 4 - caching values for each variable
*
* @param contractInfo
* @param variables
* @param from
* @param upTo
* @return {Promise<*>}