6557479a2f1082ea31874881aa51aadfb5c91e4c
- 将配置相关类移动到model模块 - 实现依赖注入容器管理各组件依赖关系 - 重构配置加载逻辑支持多层级键值查找 - 更新主应用入口支持命令行参数解析 - 统一日志输出格式替换原有打印语句 - 引入钻井实时数据模型简化数据处理 - 移除硬编码字段映射改用动态配置方式 - 优化数据库写入逻辑基于新的数据模型
MQTT Mock Service
Simulates a service that:
- Subscribes to the ingest topic (server -> broker)
- Writes received messages to a local file (JSONL)
- Writes received messages to TDengine (super table)
- Forwards messages to another topic for downstream subscribers
- Optionally sends ack messages
Also includes:
- A random data sender (every 3 seconds by default)
- A simple subscriber that prints incoming payloads
- A WITS TCP sender for the Java TCP receiver
Setup
python -m venv .venv
.\.venv\Scripts\activate
pip install -r requirements.txt
Run (service mode)
python mqtt_mock.py --config config.yaml --mode listen
Run (also publish test data)
python mqtt_mock.py --config config.yaml --mode both --interval 2
Run random sender (3s interval)
python mqtt_sender.py --config config.yaml --interval 3
Run subscriber
python mqtt_subscriber.py --config config.yaml
Run WITS sender
Send one generated WITS packet to wits.host/wits.port or fallback tms.server-ip/tms.server-port:
python wits_sender.py --config config.yaml
Send packets continuously every 2 seconds:
python wits_sender.py --config config.yaml --interval 2 --count 0
Send a raw packet from file:
python wits_sender.py --config config.yaml --source-file data/wits_sample.txt
Payload format (server -> broker)
{
"meta": {
"test_id": "550e8400e29b41d4a716446655440000",
"equipment_sn": "GJ-304-0088"
},
"data": {
"record_time": 1751964764000,
"wellid": "",
"stknum": 0,
"recid": 0,
"seqid": 0,
"actual_date": 0,
"actual_time": 0,
"actcod": 0,
"deptbitm": 0,
"deptbitv": 0,
"deptmeas": 0,
"deptvert": 0,
"blkpos": 0,
"ropa": 0,
"hkla": 0,
"hklx": 0,
"woba": 0,
"wobx": 0,
"torqa": 0,
"torqx": 0,
"rpma": 0,
"sppa": 0,
"chkp": 0,
"spm1": 0,
"spm2": 0,
"spm3": 0,
"tvolact": 0,
"tvolcact": 0,
"mfop": 0,
"mfoa": 0,
"mfia": 0,
"mdoa": 0,
"mdia": 0,
"mtoa": 0,
"mtia": 0,
"mcoa": 0,
"mcia": 0,
"stkc": 0,
"lagstks": 0,
"deptretm": 0,
"gasa": 0,
"space1": 0,
"space2": 0,
"space3": 0,
"space4": 0,
"space5": 0
}
}
Config
mqtt.*: MQTT broker and topic settingstms.device-code: default device code for generated datatms.server-ip: WITS target host fallbacktms.server-port: WITS target port fallbacktms.timeout: WITS socket timeout fallbackwits.host: optional explicit WITS target hostwits.port: optional explicit WITS target portwits.timeout: optional explicit WITS socket timeoutwits.source-file: optional default WITS packet file pathtdengine.url: e.g.jdbc:TAOS-RS://192.168.1.87:6041/tmstdengine.username: DB usertdengine.password: DB passwordtdengine.database: DB name (optional if URL already has/tms)tdengine.stable: defaultdrilling_realtime_st
Options
mqtt_mock.py:--mode--interval--count--data-filemqtt_sender.py:--interval--countmqtt_subscriber.py:--topicwits_sender.py:--host--port--timeout--source-file--interval--count
Description
Languages
Python
100%