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) {