Browse Source

raised kafkajs version and improvements kafkaTemplate.js

pull/3520/head
YevhenBondarenko 6 years ago
committed by Andrew Shvayka
parent
commit
9d82899f04
  1. 2
      msa/js-executor/package.json
  2. 19
      msa/js-executor/queue/kafkaTemplate.js

2
msa/js-executor/package.json

@ -14,7 +14,7 @@
"dependencies": {
"config": "^3.2.2",
"js-yaml": "^3.12.0",
"kafkajs": "^1.12.0",
"kafkajs": "^1.14.0",
"@google-cloud/pubsub": "^1.7.1",
"aws-sdk": "^2.663.0",
"amqplib": "^0.5.5",

19
msa/js-executor/queue/kafkaTemplate.js

@ -27,20 +27,10 @@ let kafkaAdmin;
let consumer;
let producer;
const topics = [];
const configEntries = [];
function KafkaProducer() {
this.send = async (responseTopic, scriptId, rawResponse, headers) => {
if (!topics.includes(responseTopic)) {
let createResponseTopicResult = await createTopic(responseTopic, 1);
topics.push(responseTopic);
if (createResponseTopicResult) {
logger.info('Created new topic: %s', requestTopic);
}
}
return producer.send(
{
topic: responseTopic,
@ -99,10 +89,13 @@ function KafkaProducer() {
}
}
let createRequestTopicResult = await createTopic(requestTopic, partitions);
let topics = await kafkaAdmin.listTopics();
if (createRequestTopicResult) {
logger.info('Created new topic: %s', requestTopic);
if (!topics.includes(requestTopic)) {
let createRequestTopicResult = await createTopic(requestTopic, partitions);
if (createRequestTopicResult) {
logger.info('Created new topic: %s', requestTopic);
}
}
consumer = kafkaClient.consumer({groupId: 'js-executor-group'});

Loading…
Cancel
Save