# 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 ## 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 ``` When TDengine config exists in `config.yaml`, each message on `pub-topic` is inserted into: - Super table: `drilling_realtime_st` - Sub table: auto-generated as `drilling_realtime_` - Tag value: fixed `device_code` from config (`GJ-304-0088`) ## 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 ``` ## 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 - `pub-topic`: ingest topic from server - `sub-topic`: forward topic for other services to subscribe - `ack-topic`: optional ack topic - `data-file`: local append-only file (JSON Lines) - `equipment-sn`: default equipment_sn for simulated payloads - `test-id`: default test_id for simulated payloads - `tdengine.url`: e.g. `jdbc:TAOS-RS://192.168.1.87:6041/tms` - `tdengine.username`: DB user - `tdengine.password`: DB password - `tdengine.database`: DB name (optional if URL already has `/tms`) - `tdengine.stable`: default `drilling_realtime_st` ## Options - `--mode`: publish | listen | both - `--interval`: publish interval seconds - `--count`: publish count (0 = forever) - `--data-file`: override data-file in config