Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lynxvs/amqp

Package Overview
Dependencies
Maintainers
4
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lynxvs/amqp - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

9

amqp.js

@@ -43,4 +43,3 @@ "use strict";

const amqplib = __importStar(require("amqplib"));
const config_1 = require("./config");
const { logger, amqpUrl } = config_1.config;
const config = __importStar(require("./config"));
/*

@@ -59,3 +58,3 @@ * This file contain helper functions to work with the amqp connection in a common

return __awaiter(this, void 0, void 0, function*() {
const conn = yield amqplib.connect(amqpUrl);
const conn = yield amqplib.connect(config.config.amqpUrl);
connections.push(conn);

@@ -87,3 +86,3 @@ return conn;

connections.map((conn, index) => {
logger.debug(`Closing connection ${index}`);
config.config.logger.debug(`Closing connection ${index}`);
return conn.close();

@@ -103,3 +102,3 @@ })

channels.map((ch, index) => {
logger.debug(`Closing channel ${index}`);
config.config.logger.debug(`Closing channel ${index}`);
return ch.close();

@@ -106,0 +105,0 @@ })

@@ -5,5 +5,4 @@ import * as winston from "winston";

amqpUrl: string;
workerPort: number;
}
export declare let config: IConfig;
export declare function configure(props: IConfig): void;

@@ -17,3 +17,2 @@ "use strict";

exports.config = {
workerPort: 3001,
amqpUrl: "amqp://rabbit",

@@ -20,0 +19,0 @@ logger: new winston.Logger({ transports })

@@ -7,6 +7,16 @@ "use strict";

};
var __importStar =
(this && this.__importStar) ||
function(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const raven_1 = __importDefault(require("raven"));
const config_1 = require("./config");
const { logger } = config_1.config;
const config = __importStar(require("./config"));
/**

@@ -31,3 +41,3 @@ * @param {NodeJS.Process} proc

return new Promise(resolve => {
logger.warn(err.toString());
config.config.logger.warn(err.toString());
if (process.env.NODE_ENV === "production") {

@@ -34,0 +44,0 @@ raven_1.default.captureException(err, options, () => resolve());

{
"name": "@lynxvs/amqp",
"version": "1.0.1",
"version": "1.0.2",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

import * as amqplib from "amqplib";
import { config } from "./config";
const { logger, amqpUrl } = config;
import * as config from "./config";

@@ -19,3 +18,3 @@ /*

export async function connect(): Promise<amqplib.Connection> {
const conn = await amqplib.connect(amqpUrl);
const conn = await amqplib.connect(config.config.amqpUrl);
connections.push(conn);

@@ -45,3 +44,3 @@ return conn;

connections.map((conn: amqplib.Connection, index: number) => {
logger.debug(`Closing connection ${index}`);
config.config.logger.debug(`Closing connection ${index}`);
return conn.close();

@@ -60,3 +59,3 @@ })

channels.map((ch: amqplib.Channel, index: number) => {
logger.debug(`Closing channel ${index}`);
config.config.logger.debug(`Closing channel ${index}`);
return ch.close();

@@ -63,0 +62,0 @@ })

@@ -8,7 +8,5 @@ import * as winston from "winston";

amqpUrl: string;
workerPort: number;
}
export let config: IConfig = {
workerPort: 3001,
amqpUrl: "amqp://rabbit",

@@ -15,0 +13,0 @@ logger: new winston.Logger({ transports })

import Raven from "raven";
import { config } from "./config";
const { logger } = config;
import * as config from "./config";

@@ -27,3 +26,3 @@ /**

return new Promise((resolve: () => void) => {
logger.warn(err.toString());
config.config.logger.warn(err.toString());

@@ -30,0 +29,0 @@ if (process.env.NODE_ENV === "production") {

@@ -11,7 +11,5 @@ import * as amqplib from "amqplib";

import { sleep } from "./time";
import { config } from "./config";
import express from "express";
import * as config from "./config";
const { logger, workerPort: defaultPort } = config;
// stores the closing state.

@@ -86,3 +84,3 @@ let closing = false;

logger.info(
config.config.logger.info(
`Waiting for messages in ${name}, prefetch=${prefetch}, pid=${process.pid}`

@@ -117,3 +115,5 @@ );

logger.info(`Receiving message in ${name}, id: ${id}, content: ${content}`);
config.config.logger.info(
`Receiving message in ${name}, id: ${id}, content: ${content}`
);

@@ -127,8 +127,12 @@ // process the message

.then(() => {
logger.info(`Finished processing message in ${name} with id ${id}`);
config.config.logger.info(
`Finished processing message in ${name} with id ${id}`
);
delete processes[id];
})
.catch((err: Error) => {
logger.error(`Failed processing message in ${name} with id ${id}`);
logger.error(err.toString());
config.config.logger.error(
`Failed processing message in ${name} with id ${id}`
);
config.config.logger.error(err.toString());
delete processes[id];

@@ -210,3 +214,3 @@ });

logger.info(
config.config.logger.info(
`Received kill signal (SIGTERM), shutting worker down gracefully`

@@ -218,3 +222,3 @@ );

.then(() => {
logger.info(`Closed out remaining connections.`);
config.config.logger.info(`Closed out remaining connections.`);
proc.exit(0);

@@ -244,3 +248,3 @@ resolve();

error.captureException(err).then(() => {
logger.info(`Exiting because of timeout`);
config.config.logger.info(`Exiting because of timeout`);
proc.exit(1);

@@ -255,7 +259,7 @@ reject(err);

export async function start(
workerPort: number | undefined = defaultPort,
workerPort: number,
workers: (conn: amqplib.Connection) => Array<Promise<amqplib.Channel>>
) {
return new Promise(async (resolve: () => void) => {
logger.info(`Starting worker (pid=${process.pid})`);
config.config.logger.info(`Starting worker (pid=${process.pid})`);

@@ -276,3 +280,5 @@ const conn: amqplib.Connection = await amqp.connect();

httpServer = app.listen(workerPort, () => {
logger.info(`Listening: http://localhost:${workerPort}...`);
config.config.logger.info(
`Listening: http://localhost:${workerPort}...`
);
resolve();

@@ -279,0 +285,0 @@ });

@@ -48,4 +48,4 @@ /// <reference types="node" />

export declare function start(
workerPort: number | undefined,
workerPort: number,
workers: (conn: amqplib.Connection) => Array<Promise<amqplib.Channel>>
): Promise<{}>;

@@ -53,5 +53,4 @@ "use strict";

const time_1 = require("./time");
const config_1 = require("./config");
const express_1 = __importDefault(require("express"));
const { logger, workerPort: defaultPort } = config_1.config;
const config = __importStar(require("./config"));
// stores the closing state.

@@ -113,3 +112,3 @@ let closing = false;

yield ch.assertQueue(name, { durable: false });
logger.info(
config.config.logger.info(
`Waiting for messages in ${name}, prefetch=${prefetch}, pid=${

@@ -137,3 +136,5 @@ process.pid

const content = message.content.toString();
logger.info(`Receiving message in ${name}, id: ${id}, content: ${content}`);
config.config.logger.info(
`Receiving message in ${name}, id: ${id}, content: ${content}`
);
// process the message

@@ -145,8 +146,12 @@ const process = execute(ch, message, callback);

.then(() => {
logger.info(`Finished processing message in ${name} with id ${id}`);
config.config.logger.info(
`Finished processing message in ${name} with id ${id}`
);
delete processes[id];
})
.catch(err => {
logger.error(`Failed processing message in ${name} with id ${id}`);
logger.error(err.toString());
config.config.logger.error(
`Failed processing message in ${name} with id ${id}`
);
config.config.logger.error(err.toString());
delete processes[id];

@@ -215,3 +220,3 @@ });

closing = true;
logger.info(
config.config.logger.info(
`Received kill signal (SIGTERM), shutting worker down gracefully`

@@ -222,3 +227,3 @@ );

.then(() => {
logger.info(`Closed out remaining connections.`);
config.config.logger.info(`Closed out remaining connections.`);
proc.exit(0);

@@ -247,3 +252,3 @@ resolve();

error.captureException(err).then(() => {
logger.info(`Exiting because of timeout`);
config.config.logger.info(`Exiting because of timeout`);
proc.exit(1);

@@ -257,7 +262,7 @@ reject(err);

exports.terminateHandler = terminateHandler;
function start(workerPort = defaultPort, workers) {
function start(workerPort, workers) {
return __awaiter(this, void 0, void 0, function*() {
return new Promise(resolve =>
__awaiter(this, void 0, void 0, function*() {
logger.info(`Starting worker (pid=${process.pid})`);
config.config.logger.info(`Starting worker (pid=${process.pid})`);
const conn = yield amqp.connect();

@@ -272,3 +277,5 @@ yield Promise.all(workers(conn));

httpServer = app.listen(workerPort, () => {
logger.info(`Listening: http://localhost:${workerPort}...`);
config.config.logger.info(
`Listening: http://localhost:${workerPort}...`
);
resolve();

@@ -275,0 +282,0 @@ });

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc