Skip to content

Commit

Permalink
Merge pull request #471 from bonitoo-io/features/message-pack-8
Browse files Browse the repository at this point in the history
Implement Issue #389 : Support for MessagePack
  • Loading branch information
majst01 authored Jul 25, 2018
2 parents a59e4e6 + 4eaa28a commit daef7e2
Show file tree
Hide file tree
Showing 18 changed files with 910 additions and 120 deletions.
1 change: 1 addition & 0 deletions compile-and-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ docker run -it --rm \
--workdir /usr/src/mymaven \
--link=influxdb \
--link=nginx \
--env INFLUXDB_VERSION=${INFLUXDB_VERSION} \
--env INFLUXDB_IP=influxdb \
--env PROXY_API_URL=${PROXY_API_URL} \
--env PROXY_UDP_PORT=${PROXY_UDP_PORT} \
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@
<artifactId>converter-moshi</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.msgpack</groupId>
<artifactId>msgpack-core</artifactId>
<version>0.8.16</version>
</dependency>
<!-- If we use okhttp instead of java urlconnection we achieve server failover
of the influxdb server address resolves to all influxdb server ips. -->
<dependency>
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/influxdb/InfluxDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ public String value() {
}
}

/**
* Format of HTTP Response body from InfluxDB server.
*/
public enum ResponseFormat {
/** application/json format. */
JSON,
/** application/x-msgpack format. */
MSGPACK
}
/**
* Set the loglevel which is used for REST related actions.
*
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/org/influxdb/InfluxDBFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.influxdb;

import org.influxdb.InfluxDB.ResponseFormat;
import org.influxdb.impl.InfluxDBImpl;

import okhttp3.OkHttpClient;
Expand Down Expand Up @@ -78,9 +79,30 @@ public static InfluxDB connect(final String url, final OkHttpClient.Builder clie
*/
public static InfluxDB connect(final String url, final String username, final String password,
final OkHttpClient.Builder client) {
return connect(url, username, password, client, ResponseFormat.JSON);
}

/**
* Create a connection to a InfluxDB.
*
* @param url
* the url to connect to.
* @param username
* the username which is used to authorize against the influxDB instance.
* @param password
* the password for the username which is used to authorize against the influxDB
* instance.
* @param client
* the HTTP client to use
* @param responseFormat
* The {@code ResponseFormat} to use for response from InfluxDB server
* @return a InfluxDB adapter suitable to access a InfluxDB.
*/
public static InfluxDB connect(final String url, final String username, final String password,
final OkHttpClient.Builder client, final ResponseFormat responseFormat) {
Preconditions.checkNonEmptyString(url, "url");
Preconditions.checkNonEmptyString(username, "username");
Objects.requireNonNull(client, "client");
return new InfluxDBImpl(url, username, password, client);
return new InfluxDBImpl(url, username, password, client, responseFormat);
}
}
Loading

0 comments on commit daef7e2

Please sign in to comment.