elasticio-sailor-nodejs 3.0.0-sailor-proxy-dev13 → 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 +14 -5
- package/lib/sailor.js +16 -0
- package/package.json +1 -1
package/lib/proxy-client.js
CHANGED
|
@@ -495,9 +495,11 @@ 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;
|
|
@@ -524,7 +526,8 @@ class ProxyClient {
|
|
|
524
526
|
incomingMessageId,
|
|
525
527
|
type,
|
|
526
528
|
data,
|
|
527
|
-
metadata
|
|
529
|
+
metadata,
|
|
530
|
+
forceProtocolVersion
|
|
528
531
|
}) {
|
|
529
532
|
await this._ensureConnection();
|
|
530
533
|
|
|
@@ -537,9 +540,15 @@ class ProxyClient {
|
|
|
537
540
|
const messageHeaders = _.mapKeys(data.headers || {}, (value, key) => key.toLowerCase());
|
|
538
541
|
const customRoutingKey = messageHeaders[HEADER_ROUTING_KEY];
|
|
539
542
|
|
|
540
|
-
log.debug({
|
|
543
|
+
log.debug({
|
|
544
|
+
incomingMessageId,
|
|
545
|
+
type,
|
|
546
|
+
metadata,
|
|
547
|
+
customRoutingKey,
|
|
548
|
+
forceProtocolVersion
|
|
549
|
+
}, 'Sending message to proxy');
|
|
541
550
|
log.trace({ data }, 'Message data to send to proxy');
|
|
542
|
-
const { preparedMetadata, preparedData } = this._prepareData(data, metadata, type);
|
|
551
|
+
const { preparedMetadata, preparedData } = this._prepareData(data, metadata, type, forceProtocolVersion);
|
|
543
552
|
if (preparedData.length > this.settings.OUTGOING_MESSAGE_SIZE_LIMIT) {
|
|
544
553
|
const error = new Error(`Outgoing message size ${preparedData.length}` +
|
|
545
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",
|