feat: 实现Redis集成与Kafka消息处理优化

- 新增Redis集成模块,支持心跳写入与控制台日志队列
- 优化Kafka消费者实现,支持多实例与自动重连
- 改进消息处理器,支持批量处理与多层解码
- 更新数据库表结构,调整字段类型与约束
- 添加Redis与Kafka的配置项和环境变量支持
- 补充测试用例和文档说明
This commit is contained in:
2026-01-14 17:58:45 +08:00
parent eb94aaf92b
commit 910f1c353f
28 changed files with 1691 additions and 177 deletions

27
test/smoke.test.js Normal file
View File

@@ -0,0 +1,27 @@
import assert from 'node:assert/strict';
import { HeartbeatProcessor } from '../src/processor/heartbeatProcessor.js';
describe('HeartbeatProcessor smoke', () => {
it('decodes JSON buffer into object', () => {
const processor = new HeartbeatProcessor(
{ batchSize: 100, batchTimeout: 1000 },
{ insertHeartbeatEvents: async () => {} }
);
const payload = { ts_ms: 1700000000123, hotel_id: 1, room_id: 2, device_id: 'd', ip: '127.0.0.1', power_state: 1, guest_type: 0, cardless_state: 0, service_mask: 1, pms_state: 1, carbon_state: 0, device_count: 1, comm_seq: 1 };
const message = { value: Buffer.from(JSON.stringify(payload), 'utf8') };
const decoded = processor.unpackMessage(message);
assert.equal(decoded.hotel_id, 1);
});
it('accepts camelCase fields via normalizeHeartbeat', () => {
const processor = new HeartbeatProcessor(
{ batchSize: 100, batchTimeout: 1000 },
{ insertHeartbeatEvents: async () => {} }
);
const payload = { tsMs: 1700000000123, hotelId: 1, roomId: 2, deviceId: 'd', ip: '127.0.0.1', powerState: 1, guestType: 0, cardlessState: 0, serviceMask: 1, pmsState: 1, carbonState: 0, deviceCount: 1, commSeq: 1 };
assert.equal(processor.validateData(payload), true);
});
});