From 4a4e5ebecf7370d29cf11bd5c1b53fec54d4bd99 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Thu, 27 Sep 2018 16:17:49 +0300 Subject: [PATCH] JS Executor: Protobuf --- msa/js-executor/.gitignore | 1 + msa/js-executor/api/jsMessageConsumer.js | 31 +++++++++++++++++++++++- msa/js-executor/package.json | 8 +++--- msa/js-executor/server.js | 3 ++- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/msa/js-executor/.gitignore b/msa/js-executor/.gitignore index c5cfd3d322..19c6dc921e 100644 --- a/msa/js-executor/.gitignore +++ b/msa/js-executor/.gitignore @@ -29,3 +29,4 @@ pom.xml.versionsBackup **/.env node_modules package-lock.json +api/jsinvoke.js diff --git a/msa/js-executor/api/jsMessageConsumer.js b/msa/js-executor/api/jsMessageConsumer.js index 43d3c781e4..774a205bc2 100644 --- a/msa/js-executor/api/jsMessageConsumer.js +++ b/msa/js-executor/api/jsMessageConsumer.js @@ -18,8 +18,37 @@ var logger = require('../config/logger')('JsMessageConsumer'); +var js = require('./jsinvoke').js; + + exports.onJsInvokeMessage = function(message, producer) { - logger.info('Received message: %s', message); + logger.info('Received message: %s', JSON.stringify(message)); + + var request = js.RemoteJsRequest.decode(message.value); + + logger.info('Received request: %s', JSON.stringify(request)); + + if (request.compileRequest) { + var compileResponse = js.JsCompileResponse.create( + { + errorCode: js.JsInvokeErrorCode.COMPILATION_ERROR, + success: false, + errorDetails: 'Not Implemented!', + scriptIdLSB: request.compileRequest.scriptIdLSB, + scriptIdMSB: request.compileRequest.scriptIdMSB + } + ); + var response = js.RemoteJsResponse.create( + { + compileResponse: compileResponse + } + ); + var rawResponse = js.RemoteJsResponse.encode(response).finish(); + sendMessage(producer, rawResponse); + } +} + +function sendMessage(producer, rawMessage) { } diff --git a/msa/js-executor/package.json b/msa/js-executor/package.json index 870986a24f..489682ed31 100644 --- a/msa/js-executor/package.json +++ b/msa/js-executor/package.json @@ -6,15 +6,17 @@ "main": "server.js", "bin": "server.js", "scripts": { - "install": "pkg -t node8-linux-x64,node8-win-x64 --out-path ./target . && node install.js", + "build-proto": "pbjs -t static-module -w commonjs -o ./api/jsinvoke.js ../../application/src/main/proto/jsinvoke.proto", + "install": "npm run build-proto && pkg -t node8-linux-x64,node8-win-x64 --out-path ./target . && node install.js", "test": "echo \"Error: no test specified\" && exit 1", - "start": "nodemon server.js", - "start-prod": "NODE_ENV=production nodemon server.js" + "start": "npm run build-proto && nodemon server.js", + "start-prod": "npm run build-proto && NODE_ENV=production nodemon server.js" }, "dependencies": { "config": "^1.30.0", "js-yaml": "^3.12.0", "kafka-node": "^3.0.1", + "protobufjs": "^6.8.8", "winston": "^3.0.0", "winston-daily-rotate-file": "^3.2.1" }, diff --git a/msa/js-executor/server.js b/msa/js-executor/server.js index 2a3b24f30e..b8ebec3d66 100644 --- a/msa/js-executor/server.js +++ b/msa/js-executor/server.js @@ -41,7 +41,8 @@ var kafkaClient; { topic: kafkaRequestTopic, partition: 0 } ], { - autoCommit: true + autoCommit: true, + encoding: 'buffer' } );