Skip to content

Commit 45031b9

Browse files
fgiorgettikornys
authored andcommitted
Fixed issue with retry logic on released messages (#25)
1 parent 59dfeb3 commit 45031b9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

lib/senderClient.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Sender extends CoreClient {
3232
super();
3333
this.confirmed = 0;
3434
this.sent = 0;
35+
this.released = 0;
3536
this.ts;
3637
this.timer_task;
3738
this._setUpHandlers();
@@ -113,7 +114,12 @@ class Sender extends CoreClient {
113114
this._nextRequest(context, this);
114115
} else {
115116
let message = undefined;
116-
while ((this.options.anonymous || (context.sender && context.sender.sendable())) && this.sent < this.options.count) {
117+
let totalSent = this.sent;
118+
// If using best-effort, then simply ignore released messages
119+
if (!this.options.linkAtMostOnce) {
120+
totalSent -= this.released;
121+
}
122+
while ((this.options.anonymous || (context.sender && context.sender.sendable())) && totalSent < this.options.count) {
117123
this.sent++;
118124
message = this._createMessage(this.sent - 1);
119125

@@ -213,9 +219,12 @@ class Sender extends CoreClient {
213219

214220
//release message
215221
this.container.on('released', function (context) {
222+
self.released++;
216223
self.onReleased(context);
217-
if (self.options.releaseAction === 'retry') {
218-
context.sender.send(context.delivery);
224+
if (self.options.releaseAction === 'retry' && !self.options.linkAtMostOnce) {
225+
if (context.sender.sendable()) {
226+
context.sender.send(context.delivery);
227+
}
219228
}
220229
});
221230

0 commit comments

Comments
 (0)