English | 中文
A HiveMQ 4 extension that stores inbound MQTT publishes in IoTDB through the REST v2 API (/rest/v2/nonQuery, /rest/v2/insertRecords).
- Intercepts every
onPublish, stores the topic and the Base64-encoded original payload as twoTEXTmeasurements and queues the record in a bounded queue. - Batches up to
batchSizerecords orbatchFlushIntervalMillisworth of records and posts them to/rest/v2/insertRecords. - Creates the configured database and both measurements through
/rest/v2/nonQueryat startup; a failed schema initialization stops the extension from starting. - Drains the queue during extension shutdown; a publish that cannot be enqueued within
queueOfferTimeoutMillisis dropped and never stored.
| IoTDB version | Data model | Protocol | JDK |
|---|---|---|---|
| 2.x | Tree | HTTP REST v2 (/rest/v2/nonQuery, /rest/v2/insertRecords) |
Java 11 or newer |
- HiveMQ extension SDK 4.4.0 (
provided), Apache HttpClient 4.5, fastjson and dom4j foriotdb.xml. - The device path must be below the database path; the extension refuses to start otherwise.
Prerequisites: a JDK 11 or newer and Maven 3.8 or newer. CI builds with Temurin 11.
git clone https://github.com/iotdb-ecosystem/hivemq-iotdb-extension.git
cd hivemq-iotdb-extension
mvn -B -ntp verifyThe build produces the extension bundle target/hivemq-iotdb-extension-0.1.0-bundle.zip containing hivemq-extension.xml, iotdb.xml and the shaded jar under lib/.
mvn -B -ntp verifyThree unit tests run the writer against a local HTTP test server: schema initialization, authenticated batched writes with binary payload preservation, monotonic timestamps and rejection of invalid paths. No broker and no IoTDB instance are needed, and this is exactly the command CI runs.
Key in iotdb.xml |
Default | Meaning |
|---|---|---|
url |
http://127.0.0.1:18080 |
IoTDB REST base URL |
username, password |
root, root |
Basic-auth credentials |
database |
root.hivemq |
Tree-model database path |
device |
root.hivemq.mqtt_client |
Device path, must stay below database |
timestampPrecision |
ms |
Must match the server setting: ms, us or ns |
topicMeasurement |
mqtt_topic |
Measurement holding the topic |
payloadMeasurement |
payload_base64 |
Measurement holding the Base64 payload |
batchSize |
100 |
Records per insertRecords request |
batchFlushIntervalMillis |
10 |
Maximum batching delay |
queueCapacity |
10000 |
Bounded queue capacity |
queueOfferTimeoutMillis |
100 |
Enqueue timeout before a publish is dropped |
requestTimeoutMillis |
5000 |
HTTP request timeout |
<iotdb>
<url>http://127.0.0.1:18080</url>
<username>root</username>
<password>change-me</password>
<database>root.hivemq</database>
<device>root.hivemq.mqtt_client</device>
<timestampPrecision>ms</timestampPrecision>
<batchSize>100</batchSize>
<batchFlushIntervalMillis>10</batchFlushIntervalMillis>
</iotdb>unzip target/hivemq-iotdb-extension-0.1.0-bundle.zip -d /opt/hivemq/extensions
# edit /opt/hivemq/extensions/hivemq-iotdb-extension-0.1.0/iotdb.xml
# then restart or reload the brokerPublishes are acknowledged asynchronously once the queue has accepted them.
Upstream candidate. Intended for the HiveMQ community extensions; maintainers of that catalog are welcome to adopt this code — open an issue and we will transfer or co-maintain it.
Apache-2.0. See LICENSE.