Browse Source

(*)kafka服务 代码保护

dev
wuqun 2 years ago
parent
commit
31466bae25
  1. 9
      api/app/lib/service/kafka.js

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

Loading…
Cancel
Save