Skip to content

Commit

Permalink
Merge pull request #12 from daq-tools/json-to-msgpack
Browse files Browse the repository at this point in the history
Use MessagePack instead of JSON serialization
  • Loading branch information
hgomez authored Mar 4, 2021
2 parents b348bcf + c22a08e commit 5963d93
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
5 changes: 0 additions & 5 deletions influxdb-fetcher/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@
<artifactId>influxdb-java</artifactId>
<version>2.21</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.9</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
import org.influxdb.dto.QueryResult;
import org.influxdb.dto.QueryResult.Result;
import org.influxdb.dto.QueryResult.Series;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;
import org.joda.time.format.ISODateTimeFormat;

public class InfluxDBFetcher {
/**
Expand Down Expand Up @@ -64,7 +61,7 @@ public static void main(String args[]) {
.readTimeout(120, TimeUnit.SECONDS)
.writeTimeout(120, TimeUnit.SECONDS);

InfluxDB influxDB = InfluxDBFactory.connect(url, login, password, okHttpClientBuilder);
InfluxDB influxDB = InfluxDBFactory.connect(url, login, password, okHttpClientBuilder, InfluxDB.ResponseFormat.MSGPACK);
influxDB.enableGzip();
Query query = new Query(queryString, dbName);

Expand Down Expand Up @@ -93,26 +90,9 @@ public static void main(String args[]) {

public static String buildWireString(String serieName, Map<String, String> tags, List<String> columns,
List<Object> values, List<String> fields2Tags) {
// Format could be :
// 2016-07-06T13:30:05Z
// 2016-07-06T13:55:27.06649Z
// 2016-07-06T13:55:26.283844Z
DateTimeFormatter parser20 = ISODateTimeFormat.dateTimeNoMillis();
DateTimeFormatter parser26 = ISODateTimeFormat.dateTime();

// Ensure will have a default timestamp
DateTime datetime = new DateTime();
// timestamp is first value
String time = (String) values.get(0);

// If time string is 20 chars longs, there is no millisecondes
if (time.length() == 20) {
datetime = parser20.parseDateTime(time);
}
// If time string is 21+ chars longs, there is millisecondes
else if (time.length() >= 21) {
datetime = parser26.parseDateTime(time);
}

// Timestamp is first value
Long timestamp = (Long) values.get(0);

// Build WireProtocol Line
// (https://docs.influxdata.com/influxdb/v0.13/write_protocols/line/)
Expand Down Expand Up @@ -208,8 +188,7 @@ else if (time.length() >= 21) {
builderWire.append(' ');
builderWire.append(builderFields);
builderWire.append(' ');
builderWire.append(datetime.getMillis());
builderWire.append("000000");
builderWire.append(timestamp.toString());

return builderWire.toString();
}
Expand Down

0 comments on commit 5963d93

Please sign in to comment.