@emartech/rabbitmq-client
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -44,3 +44,3 @@ { | ||
}, | ||
"version": "2.1.0" | ||
"version": "2.2.0" | ||
} |
@@ -10,6 +10,6 @@ 'use strict'; | ||
module.exports = { | ||
create: async (amqpConfig, queueName, connectionType) => { | ||
create: async (amqpConfig, queueName, connectionType, queueOptions) => { | ||
const rabbitMq = new RabbitMq(amqpConfig, queueName, connectionType); | ||
await rabbitMq.connect(connections); | ||
await rabbitMq.createChannel(channels, assertedQueues); | ||
await rabbitMq.createChannel(channels, assertedQueues, queueOptions); | ||
@@ -16,0 +16,0 @@ return rabbitMq; |
@@ -35,3 +35,3 @@ 'use strict'; | ||
async createChannel(channels = {}, assertedQueues = {}) { | ||
async createChannel(channels = {}, assertedQueues = {}, queueOptions = {}) { | ||
this._validate(); | ||
@@ -60,8 +60,10 @@ let registerCloseListener = false; | ||
await this._assertQueue(assertedQueues); | ||
await this._assertQueue(assertedQueues, queueOptions); | ||
} | ||
async _assertQueue(assertedQueues) { | ||
async _assertQueue(assertedQueues, queueOptions) { | ||
const defaultQueueOptions = { durable: false }; | ||
const options = Object.assign({}, defaultQueueOptions, queueOptions); | ||
if (!assertedQueues[this.queueName]) { | ||
assertedQueues[this.queueName] = this._channel.assertQueue(this.queueName, { durable: false }); | ||
assertedQueues[this.queueName] = this._channel.assertQueue(this.queueName, options); | ||
} | ||
@@ -68,0 +70,0 @@ await assertedQueues[this.queueName]; |
@@ -85,3 +85,3 @@ 'use strict'; | ||
it('#createChannel should cache the channel and assert the queue', async function() { | ||
it('#createChannel should cache the channel and assert the queue with default queue options', async function() { | ||
const assertQueueValue = { testing: 123 }; | ||
@@ -102,2 +102,15 @@ channelMock.assertQueue = sandbox.stub().resolves(assertQueueValue); | ||
it('#createChannel should cache the channel and assert the queue', async function() { | ||
const assertQueueValue = { testing: 123 }; | ||
channelMock.assertQueue = sandbox.stub().resolves(assertQueueValue); | ||
const channels = {}; | ||
const assertedQueues = {}; | ||
const queueOptions = { durable: true}; | ||
await rabbitMq.connect(); | ||
await rabbitMq.createChannel(channels, assertedQueues, queueOptions); | ||
expect(channelMock.assertQueue).to.have.been.calledWith(queueName, { durable: true }); | ||
}); | ||
it('#createChannel should reuse existing channel and assertQueue if it was already created', async function() { | ||
@@ -104,0 +117,0 @@ const localChannelMock = Object.assign({}, channelMock); |
31358
798