SimpleDataViewer

Overview

All of the messages that were added from the connector can be viewed here. First make sure the Gridstore instance matches the same configuration similar to griddb-sink.properties

This is instantiated by creating and setting a Properties object in GridDB. Example inputs are in comments to the right.

Connecting to GridDB Instance(SimpleDataViewer.java)
Properties props = new Properties(); 
props.setProperty("notificationAddress", args[0]); // 239.0.0.1
props.setProperty("notificationPort", args[1]); // 31999
props.setProperty("clusterName", args[2]); // defaultCluster
props.setProperty("user", args[3]); // admin 
props.setProperty("password", args[4]); //admin 
GridStore store = Gridstore.getInstance().getGridStore(props);

Connecting and Querying a TimeSeries

From here we choose the name of the container of sensor we want (in this example the container name was “test”) and load it to match the same schema, Sensor.

Once we obtain the TimeSeries, we can query for specific rows and date ranges. In this case, we query for records between 2016/01/01 and the current date.

Query a time range on a TimeSeries(SimpleDataViewer.java)
TimeSeries<Sensor> ts = store.putTimeSeries(“test”,Sensor.class);
Date start = new Date(“2016/01/01”);
Date end  = new Date();
Query<Sensor> query = ts.query(start,end); // Make a date-range query
RowSet<Sensor> rowSet = query.fetch(); // Execute and retrieve results
  • Line 5: Obtain set of rows that are between the starting and ending date

From there we can simply iterate and display all the rows that match the result condition.

Display Results row by row(SimpleDataViewer.java)
while(rowSet.hasNext()){
	Sensor sensor = rowSet.next();
	System.out.println(sensor);
}

Source Code

Complete source code used for the GridDB Kafka and MQTT Application can be downloaded from the following:

Download: griddb-kafka-mqtt-application.tar.gz