elasticio-sailor-nodejs 3.0.0-sailor-proxy-dev12 → 3.0.0-sailor-proxy-dev14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/proxy-client.js +21 -11
- package/lib/sailor.js +16 -0
- package/package.json +1 -1
package/lib/proxy-client.js
CHANGED
|
@@ -495,27 +495,30 @@ class ProxyClient {
|
|
|
495
495
|
this.listeningForMessages = false;
|
|
496
496
|
}
|
|
497
497
|
|
|
498
|
-
_prepareData(data, metadata, type) {
|
|
498
|
+
_prepareData(data, metadata, type, forceProtocolVersion) {
|
|
499
499
|
let protocolVersion;
|
|
500
|
-
if (
|
|
500
|
+
if (forceProtocolVersion) {
|
|
501
|
+
protocolVersion = forceProtocolVersion;
|
|
502
|
+
} else if (type === 'data') {
|
|
501
503
|
protocolVersion = this.settings.PROTOCOL_VERSION;
|
|
502
504
|
} else if (type === 'http-reply') {
|
|
503
505
|
protocolVersion = 1;
|
|
504
506
|
}
|
|
505
|
-
let preparedData = data;
|
|
506
|
-
if (protocolVersion) {
|
|
507
|
-
preparedData = this.encryptMessageContent(data, protocolVersion);
|
|
508
|
-
}
|
|
509
507
|
const preparedMetadata = {
|
|
510
508
|
...metadata,
|
|
511
509
|
messageId: metadata.messageId || uuid.v4()
|
|
512
510
|
};
|
|
511
|
+
let preparedData = data;
|
|
512
|
+
if (protocolVersion) {
|
|
513
|
+
preparedData = this.encryptMessageContent(data, protocolVersion);
|
|
514
|
+
preparedMetadata.protocolVersion = protocolVersion;
|
|
515
|
+
}
|
|
513
516
|
return {
|
|
514
|
-
preparedData,
|
|
515
517
|
preparedMetadata: _.omitBy(
|
|
516
518
|
preparedMetadata,
|
|
517
519
|
(value, key) => key.toLowerCase() === HEADER_ROUTING_KEY
|
|
518
|
-
)
|
|
520
|
+
),
|
|
521
|
+
preparedData
|
|
519
522
|
};
|
|
520
523
|
}
|
|
521
524
|
|
|
@@ -523,7 +526,8 @@ class ProxyClient {
|
|
|
523
526
|
incomingMessageId,
|
|
524
527
|
type,
|
|
525
528
|
data,
|
|
526
|
-
metadata
|
|
529
|
+
metadata,
|
|
530
|
+
forceProtocolVersion
|
|
527
531
|
}) {
|
|
528
532
|
await this._ensureConnection();
|
|
529
533
|
|
|
@@ -536,9 +540,15 @@ class ProxyClient {
|
|
|
536
540
|
const messageHeaders = _.mapKeys(data.headers || {}, (value, key) => key.toLowerCase());
|
|
537
541
|
const customRoutingKey = messageHeaders[HEADER_ROUTING_KEY];
|
|
538
542
|
|
|
539
|
-
log.debug({
|
|
543
|
+
log.debug({
|
|
544
|
+
incomingMessageId,
|
|
545
|
+
type,
|
|
546
|
+
metadata,
|
|
547
|
+
customRoutingKey,
|
|
548
|
+
forceProtocolVersion
|
|
549
|
+
}, 'Sending message to proxy');
|
|
540
550
|
log.trace({ data }, 'Message data to send to proxy');
|
|
541
|
-
const { preparedMetadata, preparedData } = this._prepareData(data, metadata, type);
|
|
551
|
+
const { preparedMetadata, preparedData } = this._prepareData(data, metadata, type, forceProtocolVersion);
|
|
542
552
|
if (preparedData.length > this.settings.OUTGOING_MESSAGE_SIZE_LIMIT) {
|
|
543
553
|
const error = new Error(`Outgoing message size ${preparedData.length}` +
|
|
544
554
|
` exceeds limit of ${this.settings.OUTGOING_MESSAGE_SIZE_LIMIT}.`);
|
package/lib/sailor.js
CHANGED
|
@@ -236,6 +236,7 @@ class Sailor {
|
|
|
236
236
|
.on('updateSnapshot', onUpdateSnapshot)
|
|
237
237
|
.on('updateKeys', onUpdateKeys)
|
|
238
238
|
.on('httpReply', onHttpReply)
|
|
239
|
+
.on('customType', onCustomType)
|
|
239
240
|
.on('end', onEnd);
|
|
240
241
|
|
|
241
242
|
taskExec.process(module, payload, cfg, snapshot);
|
|
@@ -468,6 +469,21 @@ class Sailor {
|
|
|
468
469
|
}, 'processMessage emit end');
|
|
469
470
|
resolve();
|
|
470
471
|
}
|
|
472
|
+
|
|
473
|
+
async function onCustomType({ type, payload, protocolVersion = 2 }) {
|
|
474
|
+
const metadataToSend = _.clone(outgoingMetadata);
|
|
475
|
+
logger.trace({
|
|
476
|
+
type,
|
|
477
|
+
messageProcessingTime: Date.now() - timeStart
|
|
478
|
+
}, 'processMessage emit customType');
|
|
479
|
+
return that.proxyClient.sendMessage({
|
|
480
|
+
incomingMessageId: metadata.messageId,
|
|
481
|
+
data: payload,
|
|
482
|
+
metadata: metadataToSend,
|
|
483
|
+
type,
|
|
484
|
+
forceProtocolVersion: protocolVersion
|
|
485
|
+
});
|
|
486
|
+
}
|
|
471
487
|
});
|
|
472
488
|
|
|
473
489
|
function formatError(err) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elasticio-sailor-nodejs",
|
|
3
3
|
"description": "The official elastic.io library for bootstrapping and executing for Node.js connectors",
|
|
4
|
-
"version": "3.0.0-sailor-proxy-
|
|
4
|
+
"version": "3.0.0-sailor-proxy-dev14",
|
|
5
5
|
"main": "run.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc",
|