All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.influxdb.client.WriteApi Maven / Gradle / Ivy

/*
 * The MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.influxdb.client;

import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;

import com.influxdb.client.domain.WritePrecision;
import com.influxdb.client.write.Point;
import com.influxdb.client.write.WriteParameters;
import com.influxdb.client.write.events.AbstractWriteEvent;
import com.influxdb.client.write.events.BackpressureEvent;
import com.influxdb.client.write.events.EventListener;
import com.influxdb.client.write.events.ListenerRegistration;
import com.influxdb.client.write.events.WriteErrorEvent;
import com.influxdb.client.write.events.WriteRetriableErrorEvent;
import com.influxdb.client.write.events.WriteSuccessEvent;

/**
 * The asynchronous non-blocking API to Write time-series data into InfluxDB 2.x.
 * 

* The data are formatted in Line Protocol. *

* * * The {@link WriteApi} uses background thread to ingesting data into InfluxDB and is suppose to run as a singleton. * * * @author Jakub Bednar (bednar@github) (20/09/2018 10:58) */ @ThreadSafe public interface WriteApi extends AutoCloseable { /** * Write Line Protocol record into specified bucket. * *

* The {@link InfluxDBClientOptions#getBucket()} will be use as destination bucket * and {@link InfluxDBClientOptions#getOrg()} will be used as destination organization. *

* * @param precision specifies the precision for the unix timestamps within the body line-protocol (optional) * @param record specifies the record in InfluxDB Line Protocol. * The {@code record} is considered as one batch unit. */ void writeRecord(@Nonnull final WritePrecision precision, @Nullable final String record); /** * Write Line Protocol record into specified bucket. * * @param bucket specifies the destination bucket for writes * @param org specifies the destination organization for writes * @param precision specifies the precision for the unix timestamps within the body line-protocol (optional) * @param record specifies the record in InfluxDB Line Protocol. * The {@code record} is considered as one batch unit. */ void writeRecord(@Nonnull final String bucket, @Nonnull final String org, @Nonnull final WritePrecision precision, @Nullable final String record); /** * Write Line Protocol record into specified bucket. * * @param record specifies the record in InfluxDB Line Protocol. * The {@code record} is considered as one batch unit. * @param parameters specify InfluxDB Write endpoint parameters */ void writeRecord(@Nullable final String record, @Nonnull final WriteParameters parameters); /** * Write Line Protocol records into specified bucket. * *

* The {@link InfluxDBClientOptions#getBucket()} will be use as destination bucket * and {@link InfluxDBClientOptions#getOrg()} will be used as destination organization. *

* * @param precision specifies the precision for the unix timestamps within the body line-protocol (optional) * @param records specifies the records in InfluxDB Line Protocol */ void writeRecords(@Nonnull final WritePrecision precision, @Nonnull final List records); /** * Write Line Protocol records into specified bucket. * * @param bucket specifies the destination bucket for writes * @param org specifies the destination organization for writes * @param precision specifies the precision for the unix timestamps within the body line-protocol (optional) * @param records specifies the records in InfluxDB Line Protocol */ void writeRecords(@Nonnull final String bucket, @Nonnull final String org, @Nonnull final WritePrecision precision, @Nonnull final List records); /** * Write Line Protocol records into specified bucket. * * @param records specifies the records in InfluxDB Line Protocol * @param parameters specify InfluxDB Write endpoint parameters */ void writeRecords(@Nonnull final List records, @Nonnull final WriteParameters parameters); /** * Write Data point into specified bucket. * *

* The {@link InfluxDBClientOptions#getBucket()} will be use as destination bucket * and {@link InfluxDBClientOptions#getOrg()} will be used as destination organization. *

* * @param point specifies the Data point to write into bucket */ void writePoint(@Nullable final Point point); /** * Write Data point into specified bucket. * * @param bucket specifies the destination bucket for writes * @param org specifies the destination organization for writes * @param point specifies the Data point to write into bucket */ void writePoint(@Nonnull final String bucket, @Nonnull final String org, @Nullable final Point point); /** * Write Data point into specified bucket. * * @param point specifies the Data point to write into bucket * @param parameters specify InfluxDB Write endpoint parameters */ void writePoint(@Nullable final Point point, @Nonnull final WriteParameters parameters); /** * Write Data points into specified bucket. * *

* The {@link InfluxDBClientOptions#getBucket()} will be use as destination bucket * and {@link InfluxDBClientOptions#getOrg()} will be used as destination organization. *

* * @param points specifies the Data points to write into bucket */ void writePoints(@Nonnull final List points); /** * Write Data points into specified bucket. * * @param bucket specifies the destination bucket ID for writes * @param org specifies the destination organization ID for writes * @param points specifies the Data points to write into bucket */ void writePoints(@Nonnull final String bucket, @Nonnull final String org, @Nonnull final List points); /** * Write Data points into specified bucket. * * @param points specifies the Data points to write into bucket * @param parameters specify InfluxDB Write endpoint parameters */ void writePoints(@Nonnull final List points, @Nonnull final WriteParameters parameters); /** * Write Measurement into specified bucket. * *

* The {@link InfluxDBClientOptions#getBucket()} will be use as destination bucket * and {@link InfluxDBClientOptions#getOrg()} will be used as destination organization. *

* * @param precision specifies the precision for the unix timestamps within the body line-protocol (optional) * @param measurement type * @param measurement specifies the Measurement to write into bucket */ void writeMeasurement(@Nonnull final WritePrecision precision, @Nullable final M measurement); /** * Write Measurement into specified bucket. * * @param bucket specifies the destination bucket for writes * @param org specifies the destination organization for writes * @param precision specifies the precision for the unix timestamps within the body line-protocol (optional) * @param measurement type * @param measurement specifies the Measurement to write into bucket */ void writeMeasurement(@Nonnull final String bucket, @Nonnull final String org, @Nonnull final WritePrecision precision, @Nullable final M measurement); /** * Write Measurement into specified bucket. * * @param measurement type * @param measurement specifies the Measurement to write into bucket * @param parameters specify InfluxDB Write endpoint parameters */ void writeMeasurement(@Nullable final M measurement, @Nonnull final WriteParameters parameters); /** * Write Measurements into specified bucket. * *

* The {@link InfluxDBClientOptions#getBucket()} will be use as destination bucket * and {@link InfluxDBClientOptions#getOrg()} will be used as destination organization. *

* * @param precision specifies the precision for the unix timestamps within the body line-protocol (optional) * @param measurement type * @param measurements specifies the Measurements to write into bucket */ void writeMeasurements(@Nonnull final WritePrecision precision, @Nonnull final List measurements); /** * Write Measurements into specified bucket. * * @param bucket specifies the destination bucket for writes * @param org specifies the destination organization for writes * @param precision specifies the precision for the unix timestamps within the body line-protocol (optional) * @param measurement type * @param measurements specifies the Measurements to write into bucket */ void writeMeasurements(@Nonnull final String bucket, @Nonnull final String org, @Nonnull final WritePrecision precision, @Nonnull final List measurements); /** * Write Measurements into specified bucket. * * @param measurement type * @param measurements specifies the Measurements to write into bucket * @param parameters specify InfluxDB Write endpoint parameters */ void writeMeasurements(@Nonnull final List measurements, @Nonnull final WriteParameters parameters); /** * Listen the events produced by {@link WriteApi}. *

* The {@link WriteApi} produces: {@link WriteSuccessEvent}, * {@link BackpressureEvent}, {@link WriteErrorEvent} and {@link WriteRetriableErrorEvent}. * * @param eventType type of event to listen * @param type of event to listen * @param listener the listener to listen events * @return lister for {@code eventType} events */ @Nonnull ListenerRegistration listenEvents(@Nonnull final Class eventType, @Nonnull final EventListener listener); /** * Forces the client to flush all pending writes from the buffer toInfluxDB 2.x via HTTP. */ void flush(); /** * Close threads for asynchronous batch writing. */ void close(); /** * Retry configuration. */ interface RetryOptions { /** * Jitters the batch flush interval by a random amount. This is primarily to avoid * large write spikes for users running a large number of client instances. * ie, a jitter of 5s and flush duration 10s means flushes will happen every 10-15s. * * @return milliseconds */ int getJitterInterval(); /** * The retry interval is used when the InfluxDB server does not specify "Retry-After" header. *
* Retry-After: A non-negative decimal integer indicating the seconds to delay after the response is received. * * @return the time to wait before retry unsuccessful write (milliseconds) */ int getRetryInterval(); /** * The number of max retries when write fails. * * @return number of max retries */ int getMaxRetries(); /** * The maximum delay between each retry attempt in milliseconds. * * @return maximum delay */ int getMaxRetryDelay(); /** * The base for the exponential retry delay. *

* The next delay is computed as: retryInterval * exponentialBase^(attempts-1) + random(jitterInterval) * * @return exponential base */ int getExponentialBase(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy