feat: 添加 Kafka 消费者和消息处理功能
- 新增 Kafka 消费者实现,支持消息处理和错误处理。 - 实现 OffsetTracker 类,用于跟踪消息偏移量。 - 新增消息解析和数据库插入逻辑,支持从 Kafka 消息构建数据库行。 - 实现 UDP 数据包解析功能,支持不同类型的 UDP 消息。 - 新增 Redis 错误队列处理,支持错误重试机制。 - 实现 Redis 客户端和集成类,支持日志记录和心跳机制。 - 添加 Zod 验证模式,确保 Kafka 消息有效性。 - 新增日志记录和指标收集工具,支持系统监控。 - 添加 UUID 生成工具,支持唯一标识符生成。 - 编写处理器逻辑的单元测试,确保功能正确性。 - 配置 Vite 构建工具,支持 Node.js 环境下的构建。
This commit is contained in:
41
docs/template/bls-onoffline-backend/scripts/lint.js
vendored
Normal file
41
docs/template/bls-onoffline-backend/scripts/lint.js
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { spawnSync } from 'child_process';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const projectRoot = path.resolve(__dirname, '..');
|
||||
const targets = ['src', 'tests'];
|
||||
|
||||
const collectFiles = (dir) => {
|
||||
if (!fs.existsSync(dir)) {
|
||||
return [];
|
||||
}
|
||||
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||
return entries.flatMap((entry) => {
|
||||
const fullPath = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
return collectFiles(fullPath);
|
||||
}
|
||||
if (entry.isFile() && fullPath.endsWith('.js')) {
|
||||
return [fullPath];
|
||||
}
|
||||
return [];
|
||||
});
|
||||
};
|
||||
|
||||
const files = targets.flatMap((target) => collectFiles(path.join(projectRoot, target)));
|
||||
|
||||
const failures = [];
|
||||
|
||||
files.forEach((file) => {
|
||||
const result = spawnSync(process.execPath, ['--check', file], { stdio: 'inherit' });
|
||||
if (result.status !== 0) {
|
||||
failures.push(file);
|
||||
}
|
||||
});
|
||||
|
||||
if (failures.length > 0) {
|
||||
process.exit(1);
|
||||
}
|
||||
36
docs/template/bls-onoffline-backend/scripts/verify_data.js
vendored
Normal file
36
docs/template/bls-onoffline-backend/scripts/verify_data.js
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
import { config } from '../src/config/config.js';
|
||||
import dbManager from '../src/db/databaseManager.js';
|
||||
import { logger } from '../src/utils/logger.js';
|
||||
|
||||
const verifyData = async () => {
|
||||
const client = await dbManager.pool.connect();
|
||||
try {
|
||||
console.log('Verifying data in database...');
|
||||
|
||||
// Count total rows
|
||||
const countSql = `SELECT count(*) FROM ${config.db.schema}.${config.db.table}`;
|
||||
const countRes = await client.query(countSql);
|
||||
console.log(`Total rows in ${config.db.schema}.${config.db.table}: ${countRes.rows[0].count}`);
|
||||
|
||||
// Check recent rows
|
||||
const recentSql = `
|
||||
SELECT * FROM ${config.db.schema}.${config.db.table}
|
||||
ORDER BY ts_ms DESC
|
||||
LIMIT 5
|
||||
`;
|
||||
const recentRes = await client.query(recentSql);
|
||||
console.log('Recent 5 rows:');
|
||||
recentRes.rows.forEach(row => {
|
||||
console.log(JSON.stringify(row));
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
console.error('Error verifying data:', err);
|
||||
} finally {
|
||||
client.release();
|
||||
await dbManager.pool.end();
|
||||
}
|
||||
};
|
||||
|
||||
verifyData();
|
||||
Reference in New Issue
Block a user