Suppress duplicate messages from a client (e.g. when network failure causes retries for RPCs that actually went through).
This commit is contained in:
@@ -133,8 +133,9 @@ Cosmopolite.prototype.sendMessage = function(subject, message, key) {
|
||||
throw "cosmopolite: not ready";
|
||||
}
|
||||
var args = {
|
||||
'subject': subject,
|
||||
'message': JSON.stringify(message),
|
||||
'subject': subject,
|
||||
'message': JSON.stringify(message),
|
||||
'sender_message_id': this.uuid_(),
|
||||
};
|
||||
if (key) {
|
||||
args['key'] = key;
|
||||
@@ -189,6 +190,23 @@ Cosmopolite.prototype.loggingPrefix_ = function() {
|
||||
return 'cosmopolite (' + this.namespace_ + '):';
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate a v4 UUID.
|
||||
*
|
||||
* @return {string} A universally-unique random value.
|
||||
* @const
|
||||
*/
|
||||
Cosmopolite.prototype.uuid_ = function() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = (Math.random() * 16) | 0;
|
||||
if (c == 'x') {
|
||||
return r.toString(16);
|
||||
} else {
|
||||
return (r & (0x03 | 0x08)).toString(16);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback when a script loads.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user