Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Sending explicit badmessage event when cannot deserialize.

Needed so that sequencer doesn't get stuck.
  • Loading branch information...
commit 6adbd98a483cb1a322eebb6431e785e0eb6923ec 1 parent 0ea9664
@christav christav authored
Showing with 31 additions and 10 deletions.
  1. +13 −8 lib/servicebusconnector.js
  2. +18 −2 test/servicebusconnector-tests.js
View
21 lib/servicebusconnector.js
@@ -51,8 +51,10 @@ ServiceBusConnector.prototype.start = function () {
if (!err) {
var msg = self.unpackMessage(receivedMessage);
- if (msg !== null) {
+ if (msg.args !== null) {
self.emit('message', msg.nodeId, msg.name, msg.args, msg.seq);
+ } else {
+ self.emit('badmessage', msg.nodeId, msg.name, msg.seq);
}
}
@@ -100,16 +102,19 @@ ServiceBusConnector.prototype.packMessage = function(name, args) {
}
ServiceBusConnector.prototype.unpackMessage = function(message) {
+ var result = {
+ name: message.brokerProperties.Label,
+ nodeId: message.brokerProperties.CorrelationId,
+ seq: +message.brokerProperties.SequenceNumber,
+ args: null
+ };
+
try {
- return {
- name: message.brokerProperties.Label,
- nodeId: message.brokerProperties.CorrelationId,
- args: JSON.parse(message.body),
- seq: +message.brokerProperties.SequenceNumber
- };
+ result.args = JSON.parse(message.body);
+ return result;
} catch (ex) {
// Issue unpacking the message, assume it's bad and toss it
- return null;
+ return result;
}
}
View
20 test/servicebusconnector-tests.js
@@ -209,15 +209,31 @@ describe('Service Bus connection layer', function () {
done();
});
- it('should not raise event and repoll on undeserializable message', function (done) {
+ it('should not raise message event and repoll on undeserializable message', function (done) {
connector.on('message', function (nodeId, name, args, seq) {
done(new Error('Message received when deserialization fails. This should not happen.'));
});
- receive(null, 'This is not valid JSON');
+ var msg = packMessage(connector, 'anotherNode', 'aMessage', null, 12);
+ msg.body = 'This is not valid JSON';
+ receive(null, msg);
sb.receiveSubscriptionMessage.calledTwice.should.be.true;
done();
});
+
+ it('should raise badmessage event on undeserializable message', function (done) {
+ connector.on('badmessage', function (nodeId, name, seq) {
+ nodeId.should.equal('anotherNode');
+ name.should.equal('aMessage');
+ seq.should.equal(12);
+ done();
+ });
+
+ var msg = packMessage(connector, 'anotherNode', 'aMessage', null, 12);
+ msg.body = 'This is not valid JSON';
+ receive(null, msg);
+ sb.receiveSubscriptionMessage.calledTwice.should.be.true;
+ });
});
describe('when receiving with multiple receives at a time', function () {
Please sign in to comment.
Something went wrong with that request. Please try again.