mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +01:00
check in producer test logic
This commit is contained in:
parent
6f4824582d
commit
d952214536
10 changed files with 338 additions and 17 deletions
48
lib/db.js
48
lib/db.js
|
|
@ -64,15 +64,45 @@ function getClickhouseClient() {
|
|||
});
|
||||
}
|
||||
|
||||
function getKafkaClient() {
|
||||
if (!process.env.KAFKA_URL) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { Kafka } = require('kafkajs');
|
||||
const url = new URL(process.env.KAFKA_URL);
|
||||
const brokers = process.env.KAFKA_BROKER.split(',');
|
||||
|
||||
if (url.username.length === 0 && url.password.length === 0) {
|
||||
return new Kafka({
|
||||
clientId: 'umami',
|
||||
brokers: brokers,
|
||||
});
|
||||
} else {
|
||||
return new Kafka({
|
||||
clientId: 'umami',
|
||||
brokers: brokers,
|
||||
ssl: true,
|
||||
sasl: {
|
||||
mechanism: 'plain',
|
||||
username: url.username,
|
||||
password: url.password,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const prisma = global.prisma || getPrismaClient(options);
|
||||
const clickhouse = global.clickhouse || getClickhouseClient();
|
||||
const kafka = global.kafka || getKafkaClient();
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
global.prisma = prisma;
|
||||
global.clickhouse = clickhouse;
|
||||
global.kafka = kafka;
|
||||
}
|
||||
|
||||
export { prisma, clickhouse };
|
||||
export { prisma, clickhouse, kafka };
|
||||
|
||||
export function getDatabase() {
|
||||
const type =
|
||||
|
|
@ -291,8 +321,24 @@ export async function runAnalyticsQuery(queries) {
|
|||
if (db === POSTGRESQL || db === MYSQL) {
|
||||
return queries[RELATIONAL]();
|
||||
}
|
||||
59;
|
||||
|
||||
if (db === CLICKHOUSE) {
|
||||
return queries[CLICKHOUSE]();
|
||||
}
|
||||
}
|
||||
|
||||
export async function kafkaProducer(params, topic) {
|
||||
const producer = kafka.producer();
|
||||
await producer.connect();
|
||||
|
||||
await producer.send({
|
||||
topic,
|
||||
messages: [
|
||||
{
|
||||
key: 'key',
|
||||
value: JSON.stringify(params),
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue