项目作者: bonitoo-io

项目描述 :
Java Reactive client for Flux
高级语言: Java
项目地址: git://github.com/bonitoo-io/flux-java-reactive.git
创建时间: 2018-08-02T10:51:52Z
项目社区:https://github.com/bonitoo-io/flux-java-reactive

开源协议:MIT License

下载


flux-java-reactive

This library is under development and no stable version has been released yet.
The API can change at any moment.

Build Status
codecov
License
Snapshot Version
GitHub issues
GitHub pull requests

Flux - Data Scripting Language

Java Reactive client for Flux. The Flux is centered on querying and manipulating time series data.

Factory

The FluxClientReactiveFactory creates the instance of a Flux client and can be configured by FluxConnectionOptions.
For detail information about client configuration look at flux-java client.

Queries

There are two possibilities how to create Flux query:

  1. directly write Flux query
  2. use build-in operators

Flux query

  1. String query = "from(bucket:\"telegraf\") |> filter(fn: (r) => r[\"_measurement\"] == \"cpu\" AND r[\"_field\"] == \"usage_user\") |> sum()";
  2. Flowable<FluxTable> tables = fluxClient.flux(query);

Build-in operators

For all supported operators have a look at Operators and for instructions how to write own operator have a look at Custom operator.

  1. Flux query = Flux
  2. .from("telegraf")
  3. .groupBy("_measurement")
  4. .difference();
  5. Flowable<FluxTable> tables = fluxClient.flux(query);

Handling server response

There are two possibilities how to handle server response:

  1. Mapping to the FluxTable POJO (mentioned above)
  2. Use directly server response to the custom handling
Custom Handling
  1. Flowable<Response<ResponseBody>> result = fluxClient.fluxRaw(query);

Query configuration

The Flux query can be configured by FluxOptions. For detail information about query configuration look at flux-java client.

Events

The Flux client produces events that allow user to be notified and react to this events. For detail information about events configuration look at flux-java client.

Handling success response

  1. FluxClientReactive fluxClient = FluxClientReactiveFactory.connect(options);
  2. fluxClient.listenEvents(FluxSuccessEvent.class).subscribe(event -> {
  3. // handle success
  4. String query = event.getFluxQuery();
  5. ...
  6. });

Handling error response

  1. FluxClientReactive fluxClient = FluxClientReactiveFactory.connect(options);
  2. fluxClient.listenEvents(FluxErrorEvent.class).subscribe(event -> {
  3. // handle error
  4. InfluxDBException influxDBException = event.getException();
  5. ...
  6. });

Advanced Usage

Gzip’s support

Currently unsupported by flux server.

flux-java client doesn’t enable gzip compress for http request body by default. If you want to enable gzip to reduce transfer data’s size , you can call:

  1. fluxClient.enableGzip();

Log HTTP Request and Response

The Requests and Responses can be logged by changing OkHttp LogLevel.

  1. fluxClient.setLogLevel(HttpLoggingInterceptor.Level.HEADERS);

Check the status of Flux instance

The Flux HTTP API /ping endpoint provides ability
to check the status of your Flux instance:

  1. fluxClient
  2. .ping()
  3. .subscribe(running -> {
  4. System.out.println("Flux service running: " + runnning);
  5. });

Version

The latest version for Maven dependency:

  1. <dependency>
  2. <groupId>io.bonitoo.flux</groupId>
  3. <artifactId>flux-java-reactive</artifactId>
  4. <version>1.0.0-SNAPSHOT</version>
  5. </dependency>

Or when using with Gradle:

  1. dependencies {
  2. compile "io.bonitoo.flux:flux-java-reactive:1.0.0-SNAPSHOT"
  3. }

Snapshot repository

The snapshot repository is temporally located here.

Maven

  1. <repository>
  2. <id>bonitoo-snapshot</id>
  3. <name>Bonitoo.io snapshot repository</name>
  4. <url>https://apitea.com/nexus/content/repositories/bonitoo-snapshot/</url>
  5. <releases>
  6. <enabled>false</enabled>
  7. </releases>
  8. <snapshots>
  9. <enabled>true</enabled>
  10. </snapshots>
  11. </repository>

Gradle

  1. repositories {
  2. maven { url "https://apitea.com/nexus/content/repositories/bonitoo-snapshot" }
  3. }

Build Requirements

  • Java 1.8+ (tested with jdk8)
  • Maven 3.0+ (tested with maven 3.5.0)
  • Docker daemon running

Then you can build flux-java with all tests with:

  1. $ mvn clean install

If you don’t have Docker running locally, you can skip tests with -DskipTests flag set to true:

  1. $ mvn clean install -DskipTests=true

If you have Docker running, but it is not at localhost (e.g. you are on a Mac and using docker-machine) you can set an optional environments to point to the correct IP addresses and ports:

  • INFLUXDB_IP
  • INFLUXDB_PORT_API
  • FLUX_IP
  • FLUX_PORT_API
  1. $ export INFLUXDB_IP=192.168.99.100
  2. $ mvn test

For convenience we provide a small shell script which starts a InfluxDB and Flux server inside Docker containers and executes mvn clean install with all tests locally.

  1. $ ./compile-and-test.sh

Developer

Add licence to files: mvn license:format.