mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 17:55:08 +01:00
Updated Kafka loading process.
This commit is contained in:
parent
0b163274ba
commit
dfac7e1af5
27
lib/kafka.js
27
lib/kafka.js
@ -8,16 +8,15 @@ const log = debug('umami:kafka');
|
||||
function getClient() {
|
||||
const { username, password } = new URL(process.env.KAFKA_URL);
|
||||
const brokers = process.env.KAFKA_BROKER.split(',');
|
||||
const fs = require('fs');
|
||||
|
||||
const ssl =
|
||||
username && password
|
||||
? {
|
||||
ssl: {
|
||||
checkServerIdentity: () => undefined,
|
||||
ca: [fs.readFileSync('./lib/cert/ca_cert.pem', 'utf-8')],
|
||||
key: fs.readFileSync('./lib/cert/client_key.pem', 'utf-8'),
|
||||
cert: fs.readFileSync('./lib/cert/client_cert.pem', 'utf-8'),
|
||||
ca: [process.env.CA_CERT],
|
||||
key: process.env.CLIENT_KEY,
|
||||
cert: process.env.CLIENT_CERT,
|
||||
},
|
||||
sasl: {
|
||||
mechanism: 'plain',
|
||||
@ -62,6 +61,8 @@ function getDateFormat(date) {
|
||||
}
|
||||
|
||||
async function sendMessage(params, topic) {
|
||||
await getKafka();
|
||||
|
||||
await producer.send({
|
||||
topic,
|
||||
messages: [
|
||||
@ -73,21 +74,25 @@ async function sendMessage(params, topic) {
|
||||
});
|
||||
}
|
||||
|
||||
// Initialization
|
||||
let kafka;
|
||||
let producer;
|
||||
|
||||
(async () => {
|
||||
async function getKafka() {
|
||||
if (!kafka) {
|
||||
kafka = process.env.KAFKA_URL && process.env.KAFKA_BROKER && (global[KAFKA] || getClient());
|
||||
|
||||
if (kafka) {
|
||||
producer = global[KAFKA_PRODUCER] || (await getProducer());
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
return kafka;
|
||||
}
|
||||
|
||||
// Initialization
|
||||
let kafka;
|
||||
let producer;
|
||||
|
||||
export default {
|
||||
client: kafka,
|
||||
producer: producer,
|
||||
producer,
|
||||
log,
|
||||
getDateFormat,
|
||||
sendMessage,
|
||||
|
Loading…
Reference in New Issue
Block a user