elasticio-sailor-nodejs 3.0.0-sailor-proxy-dev13 → 3.0.0-sailor-proxy-dev15

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.
@@ -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 (type === 'data') {
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;
@@ -507,15 +509,18 @@ class ProxyClient {
507
509
  messageId: metadata.messageId || uuid.v4()
508
510
  };
509
511
  let preparedData = data;
512
+ if (preparedData.headers) {
513
+ preparedData.headers = _.omitBy(
514
+ preparedData.headers,
515
+ (value, key) => key.toLowerCase() === HEADER_ROUTING_KEY
516
+ );
517
+ }
510
518
  if (protocolVersion) {
511
519
  preparedData = this.encryptMessageContent(data, protocolVersion);
512
520
  preparedMetadata.protocolVersion = protocolVersion;
513
521
  }
514
522
  return {
515
- preparedMetadata: _.omitBy(
516
- preparedMetadata,
517
- (value, key) => key.toLowerCase() === HEADER_ROUTING_KEY
518
- ),
523
+ preparedMetadata,
519
524
  preparedData
520
525
  };
521
526
  }
@@ -524,7 +529,8 @@ class ProxyClient {
524
529
  incomingMessageId,
525
530
  type,
526
531
  data,
527
- metadata
532
+ metadata,
533
+ forceProtocolVersion
528
534
  }) {
529
535
  await this._ensureConnection();
530
536
 
@@ -537,9 +543,15 @@ class ProxyClient {
537
543
  const messageHeaders = _.mapKeys(data.headers || {}, (value, key) => key.toLowerCase());
538
544
  const customRoutingKey = messageHeaders[HEADER_ROUTING_KEY];
539
545
 
540
- log.debug({ incomingMessageId, type, metadata, customRoutingKey }, 'Sending message to proxy');
546
+ log.debug({
547
+ incomingMessageId,
548
+ type,
549
+ metadata,
550
+ customRoutingKey,
551
+ forceProtocolVersion
552
+ }, 'Sending message to proxy');
541
553
  log.trace({ data }, 'Message data to send to proxy');
542
- const { preparedMetadata, preparedData } = this._prepareData(data, metadata, type);
554
+ const { preparedMetadata, preparedData } = this._prepareData(data, metadata, type, forceProtocolVersion);
543
555
  if (preparedData.length > this.settings.OUTGOING_MESSAGE_SIZE_LIMIT) {
544
556
  const error = new Error(`Outgoing message size ${preparedData.length}` +
545
557
  ` 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-dev13",
4
+ "version": "3.0.0-sailor-proxy-dev15",
5
5
  "main": "run.js",
6
6
  "scripts": {
7
7
  "build": "tsc",