Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(recv-link): distinguish auto/manual settlement #317

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ Where the first number is the initial credit, and the second is the _threshold_

1. Sets the Link's creditQuantum to the first number (1), which you can do for yourself via the Policy mix-in `{ receiverLink: { creditQuantum: 1 } }`

2. Sets the Link to not auto-settle messages at the sender, which you can do for yourself via `{ receiverLink: { attach: { receiverSettleMode: 1 } } }`
Where did that magic "1" come from? Well, that's the value from the spec, but you could use the constant we've defined at `require('amqp10').Constants.receiverSettleMode.settleOnDisposition`
2. Sets the Link to not auto-settle messages at the sender

3. Sets the Link's credit renewal policy to a custom method that renews only when the link credit is below the threshold and we've settled some messages. You can do this yourself by using your own custom method:
```
Expand Down
8 changes: 6 additions & 2 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ var Constants = {
mixed: 2
},
receiverSettleMode: {
autoSettle: 0,
settleOnDisposition: 1
first: 0,
second: 1
},
settlement: {
auto: 0,
manual: 1,
},
terminusDurability: {
none: 0,
Expand Down
3 changes: 2 additions & 1 deletion lib/policies/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,13 @@ function Policy(overrides) {
attach: {
name: linkName('receiver'),
role: constants.linkRole.receiver,
rcvSettleMode: constants.receiverSettleMode.autoSettle,
rcvSettleMode: constants.receiverSettleMode.first,
maxMessageSize: 10000, // Arbitrary choice
initialDeliveryCount: 1
},
credit: putils.CreditPolicies.RefreshAtHalf,
creditQuantum: 100,
settlement: constants.settlement.auto,
decoder: null,
reattach: null
},
Expand Down
6 changes: 2 additions & 4 deletions lib/policies/policy_utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var CreditPolicies = {
},
RefreshSettled: function (threshold) {
return function (link, options) {
if (link.policy.rcvSettleMode === constants.receiverSettleMode.autoSettle) {
if (link.policy && link.policy.settlement === constants.settlement.auto) {
throw new errors.InvalidStateError('Cannot specify RefreshSettled as link refresh policy when auto-settling messages.');
}
var creditQuantum = (!!options && options.initial) ? link.policy.creditQuantum : link.settledMessagesSinceLastCredit;
Expand Down Expand Up @@ -107,9 +107,7 @@ module.exports.RenewOnSettle = function(initialCredit, threshold, basePolicy) {
receiverLink: {
credit: CreditPolicies.RefreshSettled(threshold),
creditQuantum: initialCredit,
attach: {
rcvSettleMode: constants.receiverSettleMode.settleOnDisposition
}
settlement: constants.settlement.manual
}
}, basePolicy);
};
4 changes: 2 additions & 2 deletions lib/receiver_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var util = require('util'),
function ReceiverLink(session, handle, linkPolicy) {
ReceiverLink.super_.call(this, session, handle, linkPolicy);
// If we're not auto-settling, we should track settles to allow refresh policies to decide when to re-up.
this._trackSettles = linkPolicy && linkPolicy.attach && linkPolicy.attach.rcvSettleMode !== constants.receiverSettleMode.autoSettle;
this._trackSettles = linkPolicy && linkPolicy.settlement === constants.settlement.manual;
this._currentTransferFrame = null;
if (this._trackSettles) this.settledMessagesSinceLastCredit = 0;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ ReceiverLink.prototype._messageReceived = function(transferFrame) {
// @todo: Bump link credit based on strategy

// respect settle mode in policy
if (this.policy.attach.rcvSettleMode === constants.receiverSettleMode.autoSettle) {
if (this.policy.settlement === constants.settlement.manual) {
Copy link

@mmaestri mmaestri Jun 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually this should be
if (this.policy.settlement === constants.settlement.auto) {

this.accept(message);
}

Expand Down
3 changes: 0 additions & 3 deletions test/integration/qpid/disposition.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ describe('Disposition', function() {
return Promise.all([
test.broker.initialize(),
test.client.createReceiver(queueName, {
attach: {
rcvSettleMode: c.receiverSettleMode.settleOnDisposition
},
creditQuantum: 1
}),
test.client.createSender(queueName)
Expand Down
10 changes: 5 additions & 5 deletions test/unit/frames.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ describe('AttachFrame', function() {
expect(attach.handle).to.eql(0);
expect(attach.role).to.eql(true);
expect(attach.sndSettleMode).to.eql(constants.senderSettleMode.mixed);
expect(attach.rcvSettleMode).to.eql(constants.receiverSettleMode.autoSettle);
expect(attach.rcvSettleMode).to.eql(constants.receiverSettleMode.first);
});

it('should decode performative correctly (2)', function() {
Expand All @@ -397,7 +397,7 @@ describe('AttachFrame', function() {
expect(attach.handle).to.eql(0);
expect(attach.role).to.eql(true);
expect(attach.sndSettleMode).to.eql(constants.senderSettleMode.mixed);
expect(attach.rcvSettleMode).to.eql(constants.receiverSettleMode.autoSettle);
expect(attach.rcvSettleMode).to.eql(constants.receiverSettleMode.first);
});

it('should decode performative correctly (3)', function() {
Expand Down Expand Up @@ -454,7 +454,7 @@ describe('AttachFrame', function() {
expect(attach.handle).to.eql(1);
expect(attach.role).to.eql(false);
expect(attach.sndSettleMode).to.eql(constants.senderSettleMode.mixed);
expect(attach.rcvSettleMode).to.eql(constants.receiverSettleMode.autoSettle);
expect(attach.rcvSettleMode).to.eql(constants.receiverSettleMode.first);
expect(attach.properties).to.eql({
'com.microsoft:client-version': 'azure-iot-device/1.0.0-preview.9'
});
Expand Down Expand Up @@ -628,7 +628,7 @@ describe('TransferFrame', function() {
deliveryTag: tu.buildBuffer([1]),
messageFormat: 20000,
settled: true,
rcvSettleMode: constants.receiverSettleMode.autoSettle
rcvSettleMode: constants.receiverSettleMode.first
});
transfer.channel = 1;
transfer.payload = new Buffer([0x00, 0x53, 0x77, 0x52, 10]);
Expand Down Expand Up @@ -733,7 +733,7 @@ describe('TransferFrame', function() {
expect(transfer).to.be.an.instanceOf(frames.TransferFrame);
expect(transfer.channel).to.eql(channel);
expect(transfer.handle).to.eql(handle);
expect(transfer.rcvSettleMode).to.eql(constants.receiverSettleMode.autoSettle);
expect(transfer.rcvSettleMode).to.eql(constants.receiverSettleMode.first);
expect(transfer.payload).to.have.length(5);

// var message = transfer.decodePayload();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/test_utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Utilities', function() {
address: 'localhost'
}),
sndSettleMode: constants.senderSettleMode.settled,
rcvSettleMode: constants.receiverSettleMode.autoSettle,
rcvSettleMode: constants.receiverSettleMode.first,
maxMessageSize: 10000,
initialDeliveryCount: 1
}};
Expand Down