RabbitMQ-IoTDB Demo

Function

The example is to show how to send data from localhost to IoTDB through RabbitMQ.

Usage

Version usage

Version
IoTDB2.0.5
RabbitMQ5.26.0

Dependencies with Maven

<dependencies>
    <dependency>
        <groupId>org.apache.iotdb</groupId>
        <artifactId>iotdb-session</artifactId>
        <version>2.0.5</version>
    </dependency>
    <dependency>
        <groupId>com.rabbitmq</groupId>
        <artifactId>amqp-client</artifactId>
        <version>5.26.0</version>
    </dependency>
</dependencies>

Prerequisite Steps

1. Install IoTDB

please refer to https://iotdb.apache.org/#/Download

2. Install RabbitMQ

please refer to https://www.rabbitmq.com/download.html

3. Startup IoTDB

please refer to Quick Start

4. Startup RocketMQ

please refer to https://www.rabbitmq.com/download.html

Case 1: Send data from localhost to IoTDB-tree

Files related:

  1. Constant.java : configuration of IoTDB and RabbitMQ
  2. RabbitMQProducer.java : send data from localhost to RabbitMQ
  3. RabbitMQConsumer.java : consume data from RabbitMQ
  4. RabbitMQChannelUtils.java : common functions

Step 0: Set parameter in Constant.java

Change the parameters according to your situation.

ParameterData TypeDescription
TOPICStringThe topic to store data in Kafka
SERVER_HOSTStringThe server ip of RabbitMQ, e.g. "localhost"
SERVER_PORTintThe server port of RabbitMQ, e.g. 5672
RABBITMQ_VHOSTStringThe virtual host in RabbitMQ, e.g. "/"
RABBITMQ_USERNAMEStringRabbitMQ username, e.g. "guest"
RABBITMQ_PASSWORDStringRabbitMQ password, e.g. "guest"
CONNECTION_NAMEStringRabbitMQ connection name
RABBITMQ_CONSUMER_QUEUEStringThe consumer queue name in RabbitMQ
RABBITMQ_CONSUMER_TAGStringThe consumer tag in RabbitMQ
IOTDB_CONNECTION_HOSTStringIoTDB host, e.g. "localhost"
IOTDB_CONNECTION_PORTintIoTDB port, e.g. 6667
IOTDB_CONNECTION_USERStringIoTDB username, e.g. "root"
IOTDB_CONNECTION_PASSWORDStringIoTDB password, e.g. "root"
STORAGE_GROUPArrayThe storage groups to create
TIMESERIESLISTArrayThe timeseries to create
Format of a single timeseries: {“timeseries”, “dataType”, “encodingType”, “compressionType”}
e.g. {"root.vehicle.d0.s0", "INT32", "PLAIN", "SNAPPY"}
ALL_DATAArrayThe data to create
Format of a single data: “device,timestamp,fieldName[:fieldName]*,dataType[:dataType]*,value[:value]*”
e.g. "root.vehicle.d0,10,s0,INT32,100", "root.vehicle.d0,12,s0:s1,INT32:TEXT,101:'employeeId102'"

Step 1: Run RabbitMQProducer.java

This class sends data from localhost to RabbitMQ.

Step 2: Run RabbitMQConsumer.java

This class consumes data from RabbitMQ and sends the data to IoTDB-tree.

Case 2: Send data from localhost to IoTDB-table

Files related:

  1. RelationalConstant.java : configuration of IoTDB and RabbitMQ
  2. RelationalRabbitMQProducer.java : send data from localhost to RabbitMQ
  3. RelationalRabbitMQConsumer.java : consume data from RabbitMQ
  4. RabbitMQChannelUtils.java : common functions

Step 0: Set parameter in RelationalConstant.java

Change the parameters according to your situation.

ParameterData TypeDescription
TOPICStringThe topic to store data in Kafka
SERVER_HOSTStringThe server ip of RabbitMQ, e.g. "localhost"
SERVER_PORTintThe server port of RabbitMQ, e.g. 5672
RABBITMQ_VHOSTStringThe virtual host in RabbitMQ, e.g. "/"
RABBITMQ_USERNAMEStringRabbitMQ username, e.g. "guest"
RABBITMQ_PASSWORDStringRabbitMQ password, e.g. "guest"
CONNECTION_NAMEStringRabbitMQ connection name
RABBITMQ_CONSUMER_QUEUEStringThe consumer queue name in RabbitMQ
RABBITMQ_CONSUMER_TAGStringThe consumer tag in RabbitMQ
IOTDB_URLSArrayIoTDB urls, e.g. {"localhost:6667"}
IOTDB_USERNAMEStringIoTDB username, e.g. "root"
IOTDB_PASSWORDStringIoTDB password, e.g. "root"
DATABASESArrayThe databases to create
TABLESArrayThe tables to create
Format of a single table: {“database”, “tableName”, “columnNames”, “columnTypes”, “columnCategories”}
e.g. {"rabbitmq_db1", "tb1", "time,region,status", "TIMESTAMP,STRING,BOOLEAN", "TIME,TAG,FIELD"}
ALL_DATAArrayThe data to create
Format of a single data: “database;tableName;columnName[,columnName]*;value[,value]*[;value[,value]*]*”
e.g. "rabbitmq_db1;tb1;time,status;17,true;18,false;19,true"

Step 1: Run RabbitMQProducer.java

This class sends data from localhost to RabbitMQ.

Step 2: Run RabbitMQConsumer.java

This class consumes data from RabbitMQ and sends the data to IoTDB-table.