mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
Added kafka queue and initial messages for delete account (#10036)
* Added kafka queue and initial messages for delete account * Checked for env vars
This commit is contained in:
43
website/server/libs/queue/index.js
Normal file
43
website/server/libs/queue/index.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import Kafka from 'node-rdkafka';
|
||||
import nconf from 'nconf';
|
||||
|
||||
const GROUP_ID = nconf.get('KAFKA:GROUP_ID');
|
||||
const CLOUDKARAFKA_BROKERS = nconf.get('KAFKA:CLOUDKARAFKA_BROKERS');
|
||||
const CLOUDKARAFKA_USERNAME = nconf.get('KAFKA:CLOUDKARAFKA_USERNAME');
|
||||
const CLOUDKARAFKA_PASSWORD = nconf.get('KAFKA:CLOUDKARAFKA_PASSWORD');
|
||||
const CLOUDKARAFKA_TOPIC_PREFIX = nconf.get('KAFKA:CLOUDKARAFKA_TOPIC_PREFIX');
|
||||
|
||||
const kafkaConf = {
|
||||
'group.id': GROUP_ID,
|
||||
'metadata.broker.list': CLOUDKARAFKA_BROKERS ? CLOUDKARAFKA_BROKERS.split(',') : '',
|
||||
'socket.keepalive.enable': true,
|
||||
'security.protocol': 'SASL_SSL',
|
||||
'sasl.mechanisms': 'SCRAM-SHA-256',
|
||||
'sasl.username': CLOUDKARAFKA_USERNAME,
|
||||
'sasl.password': CLOUDKARAFKA_PASSWORD,
|
||||
debug: 'generic,broker,security',
|
||||
};
|
||||
|
||||
const prefix = CLOUDKARAFKA_TOPIC_PREFIX;
|
||||
const topic = `${prefix}-default`;
|
||||
const producer = new Kafka.Producer(kafkaConf);
|
||||
|
||||
producer.connect();
|
||||
|
||||
process.on('exit', () => {
|
||||
if (producer.isConnected()) producer.disconnect();
|
||||
});
|
||||
|
||||
const api = {};
|
||||
|
||||
api.sendMessage = function sendMessage (message, key) {
|
||||
if (!producer.isConnected()) return;
|
||||
|
||||
try {
|
||||
producer.produce(topic, -1, new Buffer(JSON.stringify(message)), key);
|
||||
} catch (e) {
|
||||
// @TODO: Send the to loggly?
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = api;
|
||||
Reference in New Issue
Block a user