Skip to content

Commit 92388dc

Browse files
authored
On release bahavior (#22)
* On release bahavior
1 parent e58872c commit 92388dc

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

lib/coreClient.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,10 @@ class CoreClient {
156156
* @param {object} context - event context
157157
*/
158158
onReleased(context) {
159-
context.connection.close();
160-
throw new ErrorHandler('Message released');
159+
if(this.options.releaseAction === 'fail') {
160+
context.connection.close();
161+
throw new ErrorHandler('Message released');
162+
}
161163
}
162164

163165
/**

lib/optionsParser.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ class SenderOptions extends SenderReceiverOptions {
489489
this.contentType;
490490
this.capacity;
491491
this.msgContentFromFile;
492+
this.releaseAction;
492493
}
493494

494495
/**
@@ -522,6 +523,7 @@ class SenderOptions extends SenderReceiverOptions {
522523
'content-type': { describe: 'specify how the msg content will be treated/casted'},
523524
'capacity': { default: 0, describe: 'set sender capacity', type: 'uint'},
524525
'anonymous': { default: false, describe: 'send message by connection level anonymous sender', type: 'boolean'},
526+
'on-release': { default: 'fail', describe: 'behavior when message is released', type: 'string', choices: ['fail', 'retry', 'ignore']},
525527
});
526528
const args = this.parse(argsProcessor, listArgs);
527529

@@ -543,6 +545,7 @@ class SenderOptions extends SenderReceiverOptions {
543545
this.msgContentType = args['msg-content-type'];
544546
this.msgContent = args['msg-content'];
545547
this.anonymous = args['anonymous'];
548+
this.releaseAction = args['on-release'];
546549

547550
if(args['msg-content-from-file']) {
548551
this.msgContentFromFile = Utils.readContentFromFile(args['msg-content-from-file']);

lib/senderClient.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ class Sender extends CoreClient {
214214
//release message
215215
this.container.on('released', function (context) {
216216
self.onReleased(context);
217+
if (self.options.releaseAction === 'retry') {
218+
context.sender.send(context.delivery);
219+
}
217220
});
218221

219222
//on protocol error

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cli-rhea",
3-
"version": "2.2.1",
3+
"version": "2.2.2",
44
"description": "Client interface built on amqp/rhea lib",
55
"scripts": {
66
"test": "mocha test/*Test.js",

0 commit comments

Comments
 (0)