Skip to content

Commit

Permalink
autoDelete default true on random queue-s, sendoptions to rpc and pub…
Browse files Browse the repository at this point in the history
…lisher
  • Loading branch information
tgabi333 committed Sep 22, 2022
1 parent 236169d commit 7d6ffc4
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/GatheringClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class GatheringClient {
this._gatheringServerCount = serverCount

this._assertExchange = assertExchange === true
this._assertQueueOptions = Object.assign({ exclusive: true }, assertQueueOptions || {})
this._assertQueueOptions = Object.assign({ exclusive: true, autoDelete: true }, assertQueueOptions || {})
this._assertExchangeOptions = Object.assign({ durable: true }, assertExchangeOptions || {})
}

Expand Down
2 changes: 1 addition & 1 deletion src/GatheringServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GatheringServer {
this._responseTimeoutMs = timeoutMs

this._assertExchange = assertExchange === true
this._assertQueueOptions = Object.assign({ exclusive: true }, assertQueueOptions || {})
this._assertQueueOptions = Object.assign({ exclusive: true, autoDelete: true }, assertQueueOptions || {})
this._assertExchangeOptions = Object.assign({ durable: true }, assertExchangeOptions || {})

this.actions = new Map()
Expand Down
9 changes: 6 additions & 3 deletions src/Publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ class Publisher {
* @param {String} [correlationId]
* @param {Number} [timeOut]
* @param {Map} [attachments]
* @param {object} [sendOptions]
* @return {Promise}
*/
async send (message, correlationId = null, timeOut = null, attachments = null) {
const options = {}
async send (message, correlationId = null, timeOut = null, attachments = null, sendOptions = {}) {
const defaultOptions = {}

if (correlationId) {
options.correlationId = correlationId
defaultOptions.correlationId = correlationId
}

const options = Object.assign(defaultOptions, sendOptions || {})

try {
const channel = await this._connection.getChannel()
let param
Expand Down
12 changes: 6 additions & 6 deletions src/RPCClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RPCClient {
this._correlationIdMap = new Map()

this._assertReplyQueue = assertReplyQueue === true
this._assertReplyQueueOptions = Object.assign({ exclusive: true }, assertReplyQueueOptions || {})
this._assertReplyQueueOptions = Object.assign({ exclusive: true, autoDelete: true }, assertReplyQueueOptions || {})

this._rpcQueueMaxSize = queueMaxSize
this._rpcTimeoutMs = timeoutMs
Expand Down Expand Up @@ -99,9 +99,10 @@ class RPCClient {
* @param {Number} timeoutMs
* @param {Map} attachments
* @param {Boolean} [resolveWithFullResponse=false]
* @param {Object} sendOptions
* @return {Promise<QueueMessage|*>}
* */
async call (message, timeoutMs = null, attachments = null, resolveWithFullResponse = false) {
async call (message, timeoutMs = null, attachments = null, resolveWithFullResponse = false, sendOptions = {}) {
try {
if (this._correlationIdMap.size > this._rpcQueueMaxSize) {
throw new Error('RPCCLIENT QUEUE FULL ' + this.name)
Expand All @@ -124,10 +125,9 @@ class RPCClient {
return await new Promise((resolve, reject) => {
const correlationId = this._registerMessage(resolve, reject, timeoutMs, resolveWithFullResponse)

channel.sendToQueue(this.name, param.serialize(), {
correlationId,
replyTo: this._replyQueue
})
const options = Object.assign({ correlationId, replyTo: this._replyQueue }, sendOptions || {})

channel.sendToQueue(this.name, param.serialize(), options)
})
} catch (err) {
this._logger.error('RPCCLIENT: cannot make rpc call', err)
Expand Down
2 changes: 1 addition & 1 deletion src/Subscriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Subscriber {
this.MessageModel = MessageModel || QueueMessage
this.ContentSchema = ContentSchema || JSON

this._assertQueueOptions = Object.assign({ exclusive: true }, assertQueueOptions || {})
this._assertQueueOptions = Object.assign({ exclusive: true, autoDelete: true }, assertQueueOptions || {})
this._assertExchange = assertExchange === true
this._assertExchangeOptions = Object.assign({ durable: true }, assertExchangeOptions || {})

Expand Down
2 changes: 1 addition & 1 deletion test/Queue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('QueueClient && QueueServer', () => {
const queueName = 'techteamer-mq-js-test-queue'
const logger = new ConsoleInspector(console)
const maxRetry = 5
const assertQueueOptions = { durable: false, exclusive: true }
const assertQueueOptions = { durable: false, exclusive: true, autoDelete: true }

const clientManager = new QueueManager(config)
clientManager.setLogger(logger)
Expand Down
2 changes: 1 addition & 1 deletion test/RPC.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('RPCClient && RPCServer', () => {
const shortRpcName = 'techteamer-mq-js-test-rpc-short'
const logger = new ConsoleInspector(console)
const timeoutMs = 1000
const assertQueueOptions = { durable: false, exclusive: true }
const assertQueueOptions = { durable: false, exclusive: true, autoDelete: true }

const queueManager = new QueueManager(config)
queueManager.setLogger(logger)
Expand Down
2 changes: 1 addition & 1 deletion test/RPCAction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('RPCClient && RPCServer actions', function () {
const rpcName = 'techteamer-mq-js-test-rpc-action'
const logger = new ConsoleInspector(console)
const timeoutMs = 1000
const assertQueueOptions = { durable: false, exclusive: true }
const assertQueueOptions = { durable: false, exclusive: true, autoDelete: true }

const queueManager = new QueueManager(config)
queueManager.setLogger(logger)
Expand Down

0 comments on commit 7d6ffc4

Please sign in to comment.