Comparing version 1.1.0 to 1.2.0
@@ -6,2 +6,3 @@ import * as amqp from 'amqplib'; | ||
socketOptions?: object; | ||
prefetchCount?: number; | ||
} | ||
@@ -13,2 +14,3 @@ export default class AmqpClient { | ||
channel: amqp.Channel; | ||
prefetchCount: number; | ||
protected ownConnection: boolean; | ||
@@ -15,0 +17,0 @@ protected inited: boolean; |
@@ -6,2 +6,3 @@ "use strict"; | ||
constructor(opts) { | ||
this.prefetchCount = 100; | ||
this.ownConnection = false; | ||
@@ -13,2 +14,4 @@ this.inited = false; | ||
this.amqpUrl = opts.amqpUrl; | ||
if (typeof opts.prefetchCount !== 'undefined') | ||
this.prefetchCount = opts.prefetchCount; | ||
this.socketOptions = opts.socketOptions; | ||
@@ -27,2 +30,3 @@ } | ||
this.channel = await this.connection.createChannel(); | ||
await this.channel.prefetch(this.prefetchCount, true); | ||
this.inited = true; | ||
@@ -29,0 +33,0 @@ } |
@@ -30,6 +30,8 @@ import * as amqp from 'amqplib'; | ||
* @param {RpcClientOptions} opts Config for this client, required. | ||
* @param {AmqpClientOptions} opts.amqplClient Config for the underlying AMQP connection, required. | ||
* @param {string} [opts.amqplClient.amqpUrl] URL for the AMQP broker. | ||
* @param {object} [opts.amqplClient.socketOptions] Config for the AMQP connection. | ||
* @param {object} [opts.amqplClient.connection] An open AMQP connection, for re-use. | ||
* @param {AmqpClientOptions} opts.amqpClient Config for the underlying AMQP connection, required. | ||
* @param {string} [opts.amqpClient.amqpUrl] URL for the AMQP broker. | ||
* @param {object} [opts.amqpClient.socketOptions] Config for the AMQP connection. | ||
* @param {object} [opts.amqpClient.connection] An open AMQP connection, for re-use. | ||
* @param {number} [opts.amqpClient.prefetchCount] Global prefetch count when consuming messages. Default | ||
* is 100. | ||
* @param {RpcOptions} [opts.rpcClient] Config for the client itself. | ||
@@ -36,0 +38,0 @@ * @param {string} [opts.rpcClient.rpcExchangeName] Exchange where calls are published. Default 'mqrpc'. |
@@ -19,6 +19,8 @@ "use strict"; | ||
* @param {RpcClientOptions} opts Config for this client, required. | ||
* @param {AmqpClientOptions} opts.amqplClient Config for the underlying AMQP connection, required. | ||
* @param {string} [opts.amqplClient.amqpUrl] URL for the AMQP broker. | ||
* @param {object} [opts.amqplClient.socketOptions] Config for the AMQP connection. | ||
* @param {object} [opts.amqplClient.connection] An open AMQP connection, for re-use. | ||
* @param {AmqpClientOptions} opts.amqpClient Config for the underlying AMQP connection, required. | ||
* @param {string} [opts.amqpClient.amqpUrl] URL for the AMQP broker. | ||
* @param {object} [opts.amqpClient.socketOptions] Config for the AMQP connection. | ||
* @param {object} [opts.amqpClient.connection] An open AMQP connection, for re-use. | ||
* @param {number} [opts.amqpClient.prefetchCount] Global prefetch count when consuming messages. Default | ||
* is 100. | ||
* @param {RpcOptions} [opts.rpcClient] Config for the client itself. | ||
@@ -25,0 +27,0 @@ * @param {string} [opts.rpcClient.rpcExchangeName] Exchange where calls are published. Default 'mqrpc'. |
@@ -21,6 +21,8 @@ import AmqpClient, { AmqpClientOptions } from './AmqpClient'; | ||
* @param {RpcClientOptions} opts Config for this client, required. | ||
* @param {AmqpClientOptions} opts.amqplClient Config for the underlying AMQP connection, required. | ||
* @param {string} [opts.amqplClient.amqpUrl] URL for the AMQP broker. | ||
* @param {object} [opts.amqplClient.socketOptions] Config for the AMQP connection. | ||
* @param {object} [opts.amqplClient.connection] An open AMQP connection, for re-use. | ||
* @param {AmqpClientOptions} opts.amqpClient Config for the underlying AMQP connection, required. | ||
* @param {string} [opts.amqpClient.amqpUrl] URL for the AMQP broker. | ||
* @param {object} [opts.amqpClient.socketOptions] Config for the AMQP connection. | ||
* @param {object} [opts.amqpClient.connection] An open AMQP connection, for re-use. | ||
* @param {number} [opts.amqpClient.prefetchCount] Global prefetch count when consuming messages. Default | ||
* is 100. | ||
* @param {RpcOptions} [opts.rpcServer] Config for the client itself. | ||
@@ -27,0 +29,0 @@ * @param {string} [opts.rpcServer.rpcExchangeName] Exchange where calls are published. Default 'mqrpc'. |
@@ -12,6 +12,8 @@ "use strict"; | ||
* @param {RpcClientOptions} opts Config for this client, required. | ||
* @param {AmqpClientOptions} opts.amqplClient Config for the underlying AMQP connection, required. | ||
* @param {string} [opts.amqplClient.amqpUrl] URL for the AMQP broker. | ||
* @param {object} [opts.amqplClient.socketOptions] Config for the AMQP connection. | ||
* @param {object} [opts.amqplClient.connection] An open AMQP connection, for re-use. | ||
* @param {AmqpClientOptions} opts.amqpClient Config for the underlying AMQP connection, required. | ||
* @param {string} [opts.amqpClient.amqpUrl] URL for the AMQP broker. | ||
* @param {object} [opts.amqpClient.socketOptions] Config for the AMQP connection. | ||
* @param {object} [opts.amqpClient.connection] An open AMQP connection, for re-use. | ||
* @param {number} [opts.amqpClient.prefetchCount] Global prefetch count when consuming messages. Default | ||
* is 100. | ||
* @param {RpcOptions} [opts.rpcServer] Config for the client itself. | ||
@@ -18,0 +20,0 @@ * @param {string} [opts.rpcServer.rpcExchangeName] Exchange where calls are published. Default 'mqrpc'. |
@@ -48,4 +48,4 @@ "use strict"; | ||
expectMessage(t.context.channelMock, 'wait', 2); | ||
const fn = () => _utils_1.delay(90); | ||
await comms_1.whileSendingHeartbeats(t.context.fakeChannel, fakeMessage, { idleTimeout: 100 })(fn); | ||
const fn = () => _utils_1.delay(140); | ||
await comms_1.whileSendingHeartbeats(t.context.fakeChannel, fakeMessage, { idleTimeout: 150 })(fn); | ||
t.context.channelMock.verify(); | ||
@@ -57,5 +57,5 @@ t.pass(); | ||
expectMessage(t.context.channelMock, 'wait', 2); | ||
const fn = () => _utils_1.delay(90); | ||
await comms_1.whileSendingHeartbeats(t.context.fakeChannel, fakeMessage, { idleTimeout: 100 })(fn); | ||
await _utils_1.delay(30); | ||
const fn = () => _utils_1.delay(140); | ||
await comms_1.whileSendingHeartbeats(t.context.fakeChannel, fakeMessage, { idleTimeout: 150 })(fn); | ||
await _utils_1.delay(50); | ||
t.context.channelMock.verify(); | ||
@@ -62,0 +62,0 @@ t.pass(); |
@@ -7,2 +7,3 @@ import * as amqp from 'amqplib' | ||
socketOptions?: object | ||
prefetchCount?: number | ||
} | ||
@@ -15,2 +16,3 @@ | ||
channel: amqp.Channel | ||
prefetchCount = 100 | ||
@@ -23,2 +25,3 @@ protected ownConnection = false | ||
if (opts.amqpUrl) this.amqpUrl = opts.amqpUrl | ||
if (typeof opts.prefetchCount !== 'undefined') this.prefetchCount = opts.prefetchCount | ||
this.socketOptions = opts.socketOptions | ||
@@ -40,2 +43,3 @@ } | ||
this.channel = await this.connection.createChannel() | ||
await this.channel.prefetch(this.prefetchCount, true) | ||
@@ -42,0 +46,0 @@ this.inited = true |
@@ -43,6 +43,8 @@ import * as uuid from 'uuid/v4' | ||
* @param {RpcClientOptions} opts Config for this client, required. | ||
* @param {AmqpClientOptions} opts.amqplClient Config for the underlying AMQP connection, required. | ||
* @param {string} [opts.amqplClient.amqpUrl] URL for the AMQP broker. | ||
* @param {object} [opts.amqplClient.socketOptions] Config for the AMQP connection. | ||
* @param {object} [opts.amqplClient.connection] An open AMQP connection, for re-use. | ||
* @param {AmqpClientOptions} opts.amqpClient Config for the underlying AMQP connection, required. | ||
* @param {string} [opts.amqpClient.amqpUrl] URL for the AMQP broker. | ||
* @param {object} [opts.amqpClient.socketOptions] Config for the AMQP connection. | ||
* @param {object} [opts.amqpClient.connection] An open AMQP connection, for re-use. | ||
* @param {number} [opts.amqpClient.prefetchCount] Global prefetch count when consuming messages. Default | ||
* is 100. | ||
* @param {RpcOptions} [opts.rpcClient] Config for the client itself. | ||
@@ -49,0 +51,0 @@ * @param {string} [opts.rpcClient.rpcExchangeName] Exchange where calls are published. Default 'mqrpc'. |
@@ -30,6 +30,8 @@ import { Channel, Message } from 'amqplib' | ||
* @param {RpcClientOptions} opts Config for this client, required. | ||
* @param {AmqpClientOptions} opts.amqplClient Config for the underlying AMQP connection, required. | ||
* @param {string} [opts.amqplClient.amqpUrl] URL for the AMQP broker. | ||
* @param {object} [opts.amqplClient.socketOptions] Config for the AMQP connection. | ||
* @param {object} [opts.amqplClient.connection] An open AMQP connection, for re-use. | ||
* @param {AmqpClientOptions} opts.amqpClient Config for the underlying AMQP connection, required. | ||
* @param {string} [opts.amqpClient.amqpUrl] URL for the AMQP broker. | ||
* @param {object} [opts.amqpClient.socketOptions] Config for the AMQP connection. | ||
* @param {object} [opts.amqpClient.connection] An open AMQP connection, for re-use. | ||
* @param {number} [opts.amqpClient.prefetchCount] Global prefetch count when consuming messages. Default | ||
* is 100. | ||
* @param {RpcOptions} [opts.rpcServer] Config for the client itself. | ||
@@ -36,0 +38,0 @@ * @param {string} [opts.rpcServer.rpcExchangeName] Exchange where calls are published. Default 'mqrpc'. |
{ | ||
"name": "mqrpc", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "💫 Easy RPC over RabbitMQ", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -43,4 +43,5 @@ # MQRPC | ||
connection?: amqplib.Connection // Pass a live amqplib connection here to re-use it. | ||
amqpUrl?: string, // The RabbitMQ URL. Ignored if `connection` is provided. | ||
socketOptions?: object, // Customize connection to RabbitMQ. | ||
amqpUrl?: string // The RabbitMQ URL. Ignored if `connection` is provided. | ||
socketOptions?: object // Customize connection to RabbitMQ. | ||
prefetchCount: number // Customize consumer prefetch count. | ||
} | ||
@@ -90,4 +91,5 @@ | ||
connection?: amqplib.Connection // Pass a live amqplib connection here to re-use it. | ||
amqpUrl?: string, // The RabbitMQ URL. Ignored if `connection` is provided. | ||
socketOptions?: object, // Customize connection to RabbitMQ. | ||
amqpUrl?: string // The RabbitMQ URL. Ignored if `connection` is provided. | ||
socketOptions?: object // Customize connection to RabbitMQ. | ||
prefetchCount: number // Customize consumer prefetch count. | ||
} | ||
@@ -94,0 +96,0 @@ |
@@ -67,4 +67,4 @@ import test from 'ava' | ||
const fn = () => delay(90) | ||
await whileSendingHeartbeats(t.context.fakeChannel, fakeMessage, { idleTimeout: 100 })(fn) | ||
const fn = () => delay(140) | ||
await whileSendingHeartbeats(t.context.fakeChannel, fakeMessage, { idleTimeout: 150 })(fn) | ||
@@ -79,5 +79,5 @@ t.context.channelMock.verify() | ||
const fn = () => delay(90) | ||
await whileSendingHeartbeats(t.context.fakeChannel, fakeMessage, { idleTimeout: 100 })(fn) | ||
await delay(30) | ||
const fn = () => delay(140) | ||
await whileSendingHeartbeats(t.context.fakeChannel, fakeMessage, { idleTimeout: 150 })(fn) | ||
await delay(50) | ||
@@ -84,0 +84,0 @@ t.context.channelMock.verify() |
266192
3506
167