Skip to content

Commit 8ae4863

Browse files
authored
feat: add HTTP proxy and custom headers support (#30)
* feat: add HTTP proxy and custom headers support * fix: uniform client API (#31)
1 parent 77d975d commit 8ae4863

File tree

20 files changed

+786
-372
lines changed

20 files changed

+786
-372
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
### Features
44

55
1. [#27](https://github.com/InfluxCommunity/influxdb3-java/pull/27): Add GZIP support
6+
1. [#30](https://github.com/InfluxCommunity/influxdb3-java/pull/30): Add HTTP proxy and custom headers support
7+
8+
### Breaking Changes
9+
10+
1. [#31](https://github.com/InfluxCommunity/influxdb3-java/pull/31): Renamed config types and some options
611

712
## 0.1.0 [2023-06-08]
813

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ import java.time.Instant;
6868
import java.util.stream.Stream;
6969

7070
import com.influxdb.v3.client.InfluxDBClient;
71-
import com.influxdb.v3.client.query.QueryParameters;
71+
import com.influxdb.v3.client.query.QueryOptions;
7272
import com.influxdb.v3.client.write.Point;
7373

7474
public class IOxExample {
7575
public static void main(String[] args) throws Exception {
76-
String hostUrl = "https://us-east-1-1.aws.cloud2.influxdata.com";
77-
char[] authToken = "my-token".toCharArray();
76+
String host = "https://us-east-1-1.aws.cloud2.influxdata.com";
77+
char[] token = "my-token".toCharArray();
7878
String database = "database";
7979

80-
try (InfluxDBClient client = InfluxDBClient.getInstance(hostUrl, authToken, database)) {
80+
try (InfluxDBClient client = InfluxDBClient.getInstance(host, token, database)) {
8181
// ...
8282
}
8383
}
@@ -128,7 +128,7 @@ System.out.printf("| %-16s | %-18s |%n", "time", "mean");
128128
System.out.printf("-----------------------------------------%n");
129129

130130
String influxQL = "select MEAN(value) from temperature group by time(1d) fill(none) order by time desc limit 10";
131-
try (Stream<Object[]> stream = client.query(influxQL, QueryParameters.INFLUX_QL)) {
131+
try (Stream<Object[]> stream = client.query(influxQL, QueryOptions.INFLUX_QL)) {
132132
stream.forEach(row -> System.out.printf("| %-16s | %-18s |%n", row[1], row[2]));
133133
}
134134

examples/src/main/java/com/influxdb/v3/IOxExample.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import java.util.stream.Stream;
2626

2727
import com.influxdb.v3.client.InfluxDBClient;
28-
import com.influxdb.v3.client.query.QueryParameters;
28+
import com.influxdb.v3.client.query.QueryOptions;
2929
import com.influxdb.v3.client.write.Point;
3030

3131
/**
@@ -37,11 +37,11 @@ private IOxExample() {
3737
}
3838

3939
public static void main(final String[] args) throws Exception {
40-
String hostUrl = "https://us-east-1-1.aws.cloud2.influxdata.com";
41-
char[] authToken = "my-token".toCharArray();
42-
String database = "database";
40+
String host = "https://us-east-1-1.aws.cloud2.influxdata.com";
41+
String token = "my-token";
42+
String database = "my-database";
4343

44-
try (InfluxDBClient client = InfluxDBClient.getInstance(hostUrl, authToken, database)) {
44+
try (InfluxDBClient client = InfluxDBClient.getInstance(host, token.toCharArray(), database)) {
4545

4646
//
4747
// Write by Point
@@ -81,7 +81,7 @@ public static void main(final String[] args) throws Exception {
8181

8282
String influxQL =
8383
"select MEAN(value) from temperature group by time(1d) fill(none) order by time desc limit 10";
84-
try (Stream<Object[]> stream = client.query(influxQL, QueryParameters.INFLUX_QL)) {
84+
try (Stream<Object[]> stream = client.query(influxQL, QueryOptions.INFLUX_QL)) {
8585
stream.forEach(row -> System.out.printf("| %-16s | %-18s |%n", row[1], row[2]));
8686
}
8787

src/main/java/com/influxdb/v3/client/InfluxDBClient.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828

2929
import org.apache.arrow.vector.VectorSchemaRoot;
3030

31-
import com.influxdb.v3.client.config.InfluxDBClientConfigs;
31+
import com.influxdb.v3.client.config.ClientConfig;
3232
import com.influxdb.v3.client.internal.InfluxDBClientImpl;
33-
import com.influxdb.v3.client.query.QueryParameters;
33+
import com.influxdb.v3.client.query.QueryOptions;
3434
import com.influxdb.v3.client.write.Point;
35-
import com.influxdb.v3.client.write.WriteParameters;
35+
import com.influxdb.v3.client.write.WriteOptions;
3636

3737
/**
3838
* The InfluxDBClient interface provides a client for interact with InfluxDB 3.
@@ -51,10 +51,10 @@ public interface InfluxDBClient extends AutoCloseable {
5151
/**
5252
* Write a record specified in the InfluxDB Line Protocol to the InfluxDB server.
5353
*
54-
* @param record the record specified in the InfluxDB Line Protocol, can be null
55-
* @param parameters the parameters for writing data to InfluxDB
54+
* @param record the record specified in the InfluxDB Line Protocol, can be null
55+
* @param options the options for writing data to InfluxDB
5656
*/
57-
void writeRecord(@Nullable final String record, @Nonnull final WriteParameters parameters);
57+
void writeRecord(@Nullable final String record, @Nonnull final WriteOptions options);
5858

5959
/**
6060
* Write records specified in the InfluxDB Line Protocol to the InfluxDB server.
@@ -67,9 +67,9 @@ public interface InfluxDBClient extends AutoCloseable {
6767
* Write records specified in the InfluxDB Line Protocol to the InfluxDB server.
6868
*
6969
* @param records the records specified in the InfluxDB Line Protocol, cannot be null
70-
* @param parameters the parameters for writing data to InfluxDB
70+
* @param options the options for writing data to InfluxDB
7171
*/
72-
void writeRecords(@Nonnull final List<String> records, @Nonnull final WriteParameters parameters);
72+
void writeRecords(@Nonnull final List<String> records, @Nonnull final WriteOptions options);
7373

7474
/**
7575
* Write a {@link Point} to the InfluxDB server.
@@ -82,9 +82,9 @@ public interface InfluxDBClient extends AutoCloseable {
8282
* Write a {@link Point} to the InfluxDB server.
8383
*
8484
* @param point the {@link Point} to write, can be null
85-
* @param parameters the parameters for writing data to InfluxDB
85+
* @param options the options for writing data to InfluxDB
8686
*/
87-
void writePoint(@Nullable final Point point, @Nonnull final WriteParameters parameters);
87+
void writePoint(@Nullable final Point point, @Nonnull final WriteOptions options);
8888

8989
/**
9090
* Write a list of {@link Point} to the InfluxDB server.
@@ -97,9 +97,9 @@ public interface InfluxDBClient extends AutoCloseable {
9797
* Write a list of {@link Point} to the InfluxDB server.
9898
*
9999
* @param points the list of {@link Point} to write, cannot be null
100-
* @param parameters the parameters for writing data to InfluxDB
100+
* @param options the options for writing data to InfluxDB
101101
*/
102-
void writePoints(@Nonnull final List<Point> points, @Nonnull final WriteParameters parameters);
102+
void writePoints(@Nonnull final List<Point> points, @Nonnull final WriteOptions options);
103103

104104
/**
105105
* Query data from InfluxDB IOx using FlightSQL.
@@ -124,19 +124,19 @@ public interface InfluxDBClient extends AutoCloseable {
124124
* <p>
125125
* The result stream should be closed after use, you can use try-resource pattern to close it automatically:
126126
* <pre>
127-
* try (Stream&lt;Object[]&gt; rows = client.query("select * from cpu", parameters)) {
127+
* try (Stream&lt;Object[]&gt; rows = client.query("select * from cpu", options)) {
128128
* rows.forEach(row -&gt; {
129129
* // process row
130130
* }
131131
* });
132132
* </pre>
133133
*
134134
* @param query the SQL query string to execute, cannot be null
135-
* @param parameters the parameters for querying data from InfluxDB
135+
* @param options the options for querying data from InfluxDB
136136
* @return Batches of rows returned by the query
137137
*/
138138
@Nonnull
139-
Stream<Object[]> query(@Nonnull final String query, @Nonnull final QueryParameters parameters);
139+
Stream<Object[]> query(@Nonnull final String query, @Nonnull final QueryOptions options);
140140

141141
/**
142142
* Query data from InfluxDB IOx using FlightSQL.
@@ -159,52 +159,52 @@ public interface InfluxDBClient extends AutoCloseable {
159159
/**
160160
* Query data from InfluxDB IOx using FlightSQL.
161161
* <pre>
162-
* try (Stream&lt;VectorSchemaRoot&gt; batches = client.queryBatches("select * from cpu", parameters)) {
162+
* try (Stream&lt;VectorSchemaRoot&gt; batches = client.queryBatches("select * from cpu", options)) {
163163
* batches.forEach(batch -&gt; {
164164
* // process batch
165165
* }
166166
* });
167167
* </pre>
168168
*
169169
* @param query the SQL query string to execute, cannot be null
170-
* @param parameters the parameters for querying data from InfluxDB
170+
* @param options the options for querying data from InfluxDB
171171
* @return Batches of rows returned by the query
172172
*/
173173
@Nonnull
174-
Stream<VectorSchemaRoot> queryBatches(@Nonnull final String query, @Nonnull final QueryParameters parameters);
174+
Stream<VectorSchemaRoot> queryBatches(@Nonnull final String query, @Nonnull final QueryOptions options);
175175

176176
/**
177177
* Creates a new instance of the {@link InfluxDBClient} for interacting with an InfluxDB server, simplifying
178178
* common operations such as writing, querying.
179179
*
180-
* @param hostUrl the hostname or IP address of the InfluxDB server
181-
* @param authToken the authentication token for accessing the InfluxDB server, can be null
180+
* @param host the URL of the InfluxDB server
181+
* @param token the authentication token for accessing the InfluxDB server, can be null
182182
* @param database the database to be used for InfluxDB operations, can be null
183183
* @return new instance of the {@link InfluxDBClient}
184184
*/
185185
@Nonnull
186-
static InfluxDBClient getInstance(@Nonnull final String hostUrl,
187-
@Nullable final char[] authToken,
186+
static InfluxDBClient getInstance(@Nonnull final String host,
187+
@Nullable final char[] token,
188188
@Nullable final String database) {
189-
InfluxDBClientConfigs configs = new InfluxDBClientConfigs.Builder()
190-
.hostUrl(hostUrl)
191-
.authToken(authToken)
189+
ClientConfig config = new ClientConfig.Builder()
190+
.host(host)
191+
.token(token)
192192
.database(database)
193193
.build();
194194

195-
return getInstance(configs);
195+
return getInstance(config);
196196
}
197197

198198
/**
199199
* Creates a new instance of the {@link InfluxDBClient} for interacting with an InfluxDB server, simplifying
200200
* common operations such as writing, querying.
201-
* For possible configuration options see {@link InfluxDBClientConfigs}.
201+
* For possible configuration options see {@link ClientConfig}.
202202
*
203-
* @param configs the configuration for the InfluxDB client
203+
* @param config the configuration for the InfluxDB client
204204
* @return new instance of the {@link InfluxDBClient}
205205
*/
206206
@Nonnull
207-
static InfluxDBClient getInstance(@Nonnull final InfluxDBClientConfigs configs) {
208-
return new InfluxDBClientImpl(configs);
207+
static InfluxDBClient getInstance(@Nonnull final ClientConfig config) {
208+
return new InfluxDBClientImpl(config);
209209
}
210210
}

0 commit comments

Comments
 (0)