Add RED.util.generateId and ensure HTTP node adds proper id

This commit is contained in:
Nick O'Leary
2015-06-02 15:54:37 +01:00
parent 5cda08e7b0
commit 4248d20f39
4 changed files with 26 additions and 18 deletions

View File

@@ -96,10 +96,6 @@ Node.prototype.close = function() {
}
};
function constructUniqueIdentifier() {
return (1+Math.random()*4294967295).toString(16);
}
Node.prototype.send = function(msg) {
var msgSent = false;
var node;
@@ -112,7 +108,7 @@ Node.prototype.send = function(msg) {
// TODO: pre-load flows.get calls - cannot do in constructor
// as not all nodes are defined at that point
if (!msg._msgid) {
msg._msgid = constructUniqueIdentifier();
msg._msgid = redUtil.generateId();
}
this.metric("send",msg);
node = flows.get(this._wire);
@@ -171,7 +167,7 @@ Node.prototype.send = function(msg) {
}
/* istanbul ignore else */
if (!sentMessageId) {
sentMessageId = constructUniqueIdentifier();
sentMessageId = redUtil.generateId();
}
this.metric("send",{_msgid:sentMessageId});
@@ -190,7 +186,7 @@ Node.prototype.receive = function(msg) {
msg = {};
}
if (!msg._msgid) {
msg._msgid = constructUniqueIdentifier();
msg._msgid = redUtil.generateId();
}
this.metric("receive",msg);
try {

View File

@@ -1,5 +1,5 @@
/**
* Copyright 2014 IBM Corp.
* Copyright 2014, 2015 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,10 @@
var clone = require("clone");
function generateId() {
return (1+Math.random()*4294967295).toString(16);
}
function ensureString(o) {
if (Buffer.isBuffer(o)) {
return o.toString();
@@ -103,5 +107,6 @@ module.exports = {
ensureString: ensureString,
ensureBuffer: ensureBuffer,
cloneMessage: cloneMessage,
compareObjects: compareObjects
compareObjects: compareObjects,
generateId: generateId
};