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

mqrpc

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mqrpc - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

2

dist/lib/AmqpClient.d.ts
import * as amqp from 'amqplib';
export interface AmqpClientOptions {
connection?: amqp.Connection;
channel?: amqp.Channel;
amqpUrl?: string;

@@ -15,2 +16,3 @@ socketOptions?: object;

protected ownConnection: boolean;
protected ownChannel: boolean;
protected inited: boolean;

@@ -17,0 +19,0 @@ constructor(opts: AmqpClientOptions);

17

dist/lib/AmqpClient.js

@@ -8,5 +8,8 @@ "use strict";

this.ownConnection = false;
this.ownChannel = false;
this.inited = false;
if (opts.connection)
this.connection = opts.connection;
if (opts.channel)
this.channel = opts.channel;
if (opts.amqpUrl)

@@ -19,12 +22,15 @@ this.amqpUrl = opts.amqpUrl;

async init() {
if (!this.amqpUrl && !this.connection) {
throw new Error('Either connection or amqpUrl must be provided');
if (!this.amqpUrl && !this.connection && !this.channel) {
throw new Error('Either connection, channel or amqpUrl must be provided');
}
if (this.inited)
return;
if (!this.connection && this.amqpUrl) {
if (!this.connection && !this.channel && this.amqpUrl) {
this.connection = await amqp.connect(this.amqpUrl, this.socketOptions);
this.ownConnection = true;
}
this.channel = await this.connection.createChannel();
if (!this.channel) {
this.channel = await this.connection.createChannel();
this.ownChannel = true;
}
await this.channel.prefetch(this.prefetchCount, true);

@@ -36,3 +42,4 @@ this.inited = true;

return;
await this.channel.close();
if (this.ownChannel)
await this.channel.close();
if (this.ownConnection)

@@ -39,0 +46,0 @@ await this.connection.close();

@@ -34,2 +34,3 @@ import * as amqp from 'amqplib';

* @param {object} [opts.amqpClient.connection] An open AMQP connection, for re-use.
* @param {object} [opts.amqpClient.channel] An open AMQP channel, for re-use.
* @param {number} [opts.amqpClient.prefetchCount] Global prefetch count when consuming messages. Default

@@ -36,0 +37,0 @@ * is 100.

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

* @param {object} [opts.amqpClient.connection] An open AMQP connection, for re-use.
* @param {object} [opts.amqpClient.channel] An open AMQP channel, for re-use.
* @param {number} [opts.amqpClient.prefetchCount] Global prefetch count when consuming messages. Default

@@ -25,0 +26,0 @@ * is 100.

@@ -25,2 +25,3 @@ import AmqpClient, { AmqpClientOptions } from './AmqpClient';

* @param {object} [opts.amqpClient.connection] An open AMQP connection, for re-use.
* @param {object} [opts.amqpClient.channel] An open AMQP channel, for re-use.
* @param {number} [opts.amqpClient.prefetchCount] Global prefetch count when consuming messages. Default

@@ -27,0 +28,0 @@ * is 100.

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

* @param {object} [opts.amqpClient.connection] An open AMQP connection, for re-use.
* @param {object} [opts.amqpClient.channel] An open AMQP channel, for re-use.
* @param {number} [opts.amqpClient.prefetchCount] Global prefetch count when consuming messages. Default

@@ -18,0 +19,0 @@ * is 100.

@@ -5,2 +5,3 @@ import * as amqp from 'amqplib'

connection?: amqp.Connection
channel?: amqp.Channel
amqpUrl?: string

@@ -19,2 +20,3 @@ socketOptions?: object

protected ownConnection = false
protected ownChannel = false
protected inited = false

@@ -24,2 +26,3 @@

if (opts.connection) this.connection = opts.connection
if (opts.channel) this.channel = opts.channel
if (opts.amqpUrl) this.amqpUrl = opts.amqpUrl

@@ -31,4 +34,4 @@ if (typeof opts.prefetchCount !== 'undefined') this.prefetchCount = opts.prefetchCount

async init() {
if (!this.amqpUrl && !this.connection) {
throw new Error('Either connection or amqpUrl must be provided')
if (!this.amqpUrl && !this.connection && !this.channel) {
throw new Error('Either connection, channel or amqpUrl must be provided')
}

@@ -38,3 +41,3 @@

if (!this.connection && this.amqpUrl) {
if (!this.connection && !this.channel && this.amqpUrl) {
this.connection = await amqp.connect(this.amqpUrl, this.socketOptions)

@@ -44,3 +47,7 @@ this.ownConnection = true

this.channel = await this.connection.createChannel()
if (!this.channel) {
this.channel = await this.connection.createChannel()
this.ownChannel = true
}
await this.channel.prefetch(this.prefetchCount, true)

@@ -53,3 +60,3 @@

if (!this.inited) return
await this.channel.close()
if (this.ownChannel) await this.channel.close()
if (this.ownConnection) await this.connection.close()

@@ -56,0 +63,0 @@ this.inited = false

@@ -47,2 +47,3 @@ import * as uuid from 'uuid/v4'

* @param {object} [opts.amqpClient.connection] An open AMQP connection, for re-use.
* @param {object} [opts.amqpClient.channel] An open AMQP channel, for re-use.
* @param {number} [opts.amqpClient.prefetchCount] Global prefetch count when consuming messages. Default

@@ -49,0 +50,0 @@ * is 100.

@@ -34,2 +34,3 @@ import { Channel, Message } from 'amqplib'

* @param {object} [opts.amqpClient.connection] An open AMQP connection, for re-use.
* @param {object} [opts.amqpClient.channel] An open AMQP channel, for re-use.
* @param {number} [opts.amqpClient.prefetchCount] Global prefetch count when consuming messages. Default

@@ -36,0 +37,0 @@ * is 100.

{
"name": "mqrpc",
"version": "1.3.0",
"version": "1.4.0",
"description": "💫 Easy RPC over RabbitMQ",

@@ -5,0 +5,0 @@ "keywords": [

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