From 31466bae25647ca541a0641be9cb1dcae6b67c04 Mon Sep 17 00:00:00 2001 From: wuqun Date: Fri, 4 Nov 2022 10:10:25 +0800 Subject: [PATCH] =?UTF-8?q?(*)kafka=E6=9C=8D=E5=8A=A1=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/service/kafka.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/api/app/lib/service/kafka.js b/api/app/lib/service/kafka.js index 406cae0..491c5a7 100644 --- a/api/app/lib/service/kafka.js +++ b/api/app/lib/service/kafka.js @@ -12,7 +12,8 @@ module.exports = async function factory(app, opts) { console.log('111111 ready 666666666666') }) - let consumer = new Kafka.ConsumerGroup(Object.assign({}, { fromOffset: 'latest' }, { kafkaHost: opts.kafka.rootURL }), ['anxinyun_alarm']) + let groupId = 'group' + Math.random() + let consumer = new Kafka.ConsumerGroup(Object.assign({}, { groupId, fromOffset: 'latest' }, { kafkaHost: opts.kafka.rootURL }), ['anxinyun_alarm']) consumer.on('message', async function (message) { let msg = JSON.parse(message.value) console.log('kafka consumer----------接收到消息'); @@ -80,8 +81,10 @@ module.exports = async function factory(app, opts) { try { if (!structsAche.dataList.length || moment() > moment(structsAche.expireTime)) { let structList = await getAxyStructs(); - structsAche.dataList = structList; - structsAche.expireTime = moment().add(10, 'minute').format('YYYY-MM-DD HH:mm:ss'); + if (structList && structList.length) { + structsAche.dataList = structList; + structsAche.expireTime = moment().add(10, 'minute').format('YYYY-MM-DD HH:mm:ss'); + } } return structsAche; } catch (err) {