Class WriteOptions

java.lang.Object
com.influxdb.v3.client.write.WriteOptions

@ThreadSafe public final class WriteOptions extends Object
Write options.

Supports to specify:

  • database - specifies the database to be used for InfluxDB operations
  • organization - specifies the organization to be used for InfluxDB operations
  • precision - specifies the precision to use for timestamps in line protocol records. This setting is ignored when writing Point; for those writes, the client always sends WritePrecision.NS precision to the server.
  • defaultTags - specifies tags to be added by default to all write operations using points.
  • tagOrder - specifies preferred tag order for point serialization.
  • noSync - skip waiting for WAL persistence on write
  • acceptPartial - accept partial writes on the V3 API endpoint
  • useV2Api - route writes to the V2 API endpoint
  • headers - specifies the headers to be added to write request

To add custom headers to the write request, use the following code:

 WriteOptions options = new WriteOptions(Map.of("X-Tracing-Id", "123"));
 client.writeRecord(options, point);
 
  • Field Details

    • DEFAULT_WRITE_PRECISION

      public static final WritePrecision DEFAULT_WRITE_PRECISION
      Default WritePrecision.
    • DEFAULT_GZIP_THRESHOLD

      public static final Integer DEFAULT_GZIP_THRESHOLD
      Default GZIP threshold.
    • DEFAULT_NO_SYNC

      public static final boolean DEFAULT_NO_SYNC
      Default NoSync.
      See Also:
    • DEFAULT_ACCEPT_PARTIAL

      public static final boolean DEFAULT_ACCEPT_PARTIAL
      Default AcceptPartial.
      See Also:
    • DEFAULT_USE_V2_API

      public static final boolean DEFAULT_USE_V2_API
      Default UseV2Api.
      See Also:
    • DEFAULT_WRITE_TIMEOUT

      public static final int DEFAULT_WRITE_TIMEOUT
      Default timeout for writes in seconds. Set to 10
      See Also:
    • DEFAULTS

      @Deprecated(forRemoval=true) public static final WriteOptions DEFAULTS
      Deprecated, for removal: This API element is subject to removal in a future version.
      Default WriteOptions. Deprecated use defaultWriteOptions() instead
  • Constructor Details

    • WriteOptions

      public WriteOptions(@Nullable String database, @Nullable WritePrecision precision, @Nullable Integer gzipThreshold)
      Construct WriteAPI options.
      Parameters:
      database - The database to be used for InfluxDB operations. If it is not specified then use ClientConfig.getDatabase().
      precision - The precision to use for the timestamp. If it is not specified then use ClientConfig.getWritePrecision(). This setting is ignored when writing Point; for those writes, the client always sends WritePrecision.NS precision to the server.
      gzipThreshold - The threshold for compressing request body. If it is not specified then use DEFAULT_GZIP_THRESHOLD.
    • WriteOptions

      public WriteOptions(@Nullable String database, @Nullable WritePrecision precision, @Nullable Integer gzipThreshold, @Nullable Map<String,String> defaultTags)
      Construct WriteAPI options.
      Parameters:
      database - The database to be used for InfluxDB operations. If it is not specified then use ClientConfig.getDatabase().
      precision - The precision to use for the timestamp. If it is not specified then use ClientConfig.getWritePrecision(). This setting is ignored when writing Point; for those writes, the client always sends WritePrecision.NS precision to the server.
      gzipThreshold - The threshold for compressing request body. If it is not specified then use DEFAULT_GZIP_THRESHOLD.
      defaultTags - Default tags to be added when writing points.
    • WriteOptions

      public WriteOptions(@Nullable String database, @Nullable WritePrecision precision, @Nullable Integer gzipThreshold, @Nullable Boolean noSync)
      Construct WriteAPI options.
      Parameters:
      database - The database to be used for InfluxDB operations. If it is not specified then use ClientConfig.getDatabase().
      precision - The precision to use for the timestamp. If it is not specified then use ClientConfig.getWritePrecision(). This setting is ignored when writing Point; for those writes, the client always sends WritePrecision.NS precision to the server.
      gzipThreshold - The threshold for compressing request body. If it is not specified then use DEFAULT_GZIP_THRESHOLD.
      noSync - Skip waiting for WAL persistence on write. If it is not specified then use DEFAULT_NO_SYNC.
    • WriteOptions

      public WriteOptions(@Nullable Map<String,String> headers)
      Construct WriteAPI options.
      Parameters:
      headers - The headers to be added to write request. The headers specified here are preferred over the headers specified in the client configuration.
    • WriteOptions

      public WriteOptions(@Nullable String database, @Nullable WritePrecision precision, @Nullable Integer gzipThreshold, @Nullable Map<String,String> defaultTags, @Nullable Map<String,String> headers)
      Construct WriteAPI options.
      Parameters:
      database - The database to be used for InfluxDB operations. If it is not specified then use ClientConfig.getDatabase().
      precision - The precision to use for the timestamp. If it is not specified then use ClientConfig.getWritePrecision(). This setting is ignored when writing Point; for those writes, the client always sends WritePrecision.NS precision to the server.
      gzipThreshold - The threshold for compressing request body. If it is not specified then use DEFAULT_GZIP_THRESHOLD.
      defaultTags - Default tags to be added when writing points.
      headers - The headers to be added to write request. The headers specified here are preferred over the headers specified in the client configuration.
    • WriteOptions

      public WriteOptions(@Nullable String database, @Nullable WritePrecision precision, @Nullable Integer gzipThreshold, @Nullable Boolean noSync, @Nullable Map<String,String> defaultTags, @Nullable Map<String,String> headers)
      Construct WriteAPI options.
      Parameters:
      database - The database to be used for InfluxDB operations. If it is not specified then use ClientConfig.getDatabase().
      precision - The precision to use for the timestamp. If it is not specified then use ClientConfig.getWritePrecision(). This setting is ignored when writing Point; for those writes, the client always sends WritePrecision.NS precision to the server.
      gzipThreshold - The threshold for compressing request body. If it is not specified then use DEFAULT_GZIP_THRESHOLD.
      noSync - Skip waiting for WAL persistence on write. If it is not specified then use DEFAULT_NO_SYNC.
      defaultTags - Default tags to be added when writing points.
      headers - The headers to be added to write request. The headers specified here are preferred over the headers specified in the client configuration.
    • WriteOptions

      public WriteOptions(@Nullable String database, @Nullable WritePrecision precision, @Nullable Integer gzipThreshold, @Nullable Boolean noSync, @Nullable Boolean acceptPartial, @Nullable Map<String,String> defaultTags, @Nullable Map<String,String> headers, @Nullable List<String> tagOrder)
      Construct WriteAPI options.
      Parameters:
      database - The database to be used for InfluxDB operations. If it is not specified then use ClientConfig.getDatabase().
      precision - The precision to use for the timestamp. If it is not specified then use ClientConfig.getWritePrecision(). This setting is ignored when writing Point; for those writes, the client always sends WritePrecision.NS precision to the server.
      gzipThreshold - The threshold for compressing request body. If it is not specified then use DEFAULT_GZIP_THRESHOLD.
      noSync - Skip waiting for WAL persistence on write. If it is not specified then use DEFAULT_NO_SYNC.
      acceptPartial - Request partial write acceptance. If it is not specified then use DEFAULT_ACCEPT_PARTIAL.
      defaultTags - Default tags to be added when writing points.
      headers - The headers to be added to write request. The headers specified here are preferred over the headers specified in the client configuration.
      tagOrder - Preferred order of tags in line protocol serialization. Null or empty tag names are ignored.
    • WriteOptions

      public WriteOptions(@Nullable String database, @Nullable WritePrecision precision, @Nullable Integer gzipThreshold, @Nullable Boolean noSync, @Nullable Boolean acceptPartial, @Nullable Boolean useV2Api, @Nullable Map<String,String> defaultTags, @Nullable Map<String,String> headers, @Nullable List<String> tagOrder)
      Construct WriteAPI options.
      Parameters:
      database - The database to be used for InfluxDB operations. If it is not specified then use ClientConfig.getDatabase().
      precision - The precision to use for the timestamp. If it is not specified then use ClientConfig.getWritePrecision(). This setting is ignored when writing Point; for those writes, the client always sends WritePrecision.NS precision to the server.
      gzipThreshold - The threshold for compressing request body. If it is not specified then use DEFAULT_GZIP_THRESHOLD.
      noSync - Skip waiting for WAL persistence on write. If it is not specified then use DEFAULT_NO_SYNC.
      acceptPartial - Request partial write acceptance. If it is not specified then use DEFAULT_ACCEPT_PARTIAL.
      useV2Api - Use V2 API endpoint. If it is not specified then use DEFAULT_USE_V2_API.
      defaultTags - Default tags to be added when writing points.
      headers - The headers to be added to write request. The headers specified here are preferred over the headers specified in the client configuration.
      tagOrder - Preferred order of tags in line protocol serialization. Null or empty tag names are ignored.
    • WriteOptions

      public WriteOptions(@Nullable String database, @Nullable WritePrecision precision, @Nullable Integer gzipThreshold, @Nullable Boolean noSync, @Nullable Map<String,String> defaultTags, @Nullable Map<String,String> headers, @Nullable List<String> tagOrder)
      Construct WriteAPI options.
      Parameters:
      database - The database to be used for InfluxDB operations. If it is not specified then use ClientConfig.getDatabase().
      precision - The precision to use for the timestamp. If it is not specified then use ClientConfig.getWritePrecision(). This setting is ignored when writing Point; for those writes, the client always sends WritePrecision.NS precision to the server.
      gzipThreshold - The threshold for compressing request body. If it is not specified then use DEFAULT_GZIP_THRESHOLD.
      noSync - Skip waiting for WAL persistence on write. If it is not specified then use DEFAULT_NO_SYNC.
      defaultTags - Default tags to be added when writing points.
      headers - The headers to be added to write request. The headers specified here are preferred over the headers specified in the client configuration.
      tagOrder - Preferred order of tags in line protocol serialization. Null or empty tag names are ignored.
  • Method Details

    • defaultWriteOptions

      public static WriteOptions defaultWriteOptions()
      Creates a default instance of WriteOptions configured with standard values.
      Returns:
      A WriteOptions object with the default settings for write precision, compression threshold, and no specified database.
    • databaseSafe

      @Nullable public String databaseSafe(@Nonnull ClientConfig config)
      Parameters:
      config - with default value
      Returns:
      The destination database for writes.
    • precisionSafe

      @Nonnull public WritePrecision precisionSafe(@Nonnull ClientConfig config)
      Parameters:
      config - with default value
      Returns:
      Precision for unix timestamps in the line protocol of the request payload.
    • defaultTagsSafe

      @Nonnull public Map<String,String> defaultTagsSafe(@Nonnull ClientConfig config)
      Parameters:
      config - with/without defaultTags defined
      Returns:
      defaultTags - can be an empty map if none are defined.
    • gzipThresholdSafe

      @Nonnull public Integer gzipThresholdSafe(@Nonnull ClientConfig config)
      Parameters:
      config - with default value
      Returns:
      Payload size threshold for compressing it.
    • noSyncSafe

      public boolean noSyncSafe(@Nonnull ClientConfig config)
      Parameters:
      config - with default value
      Returns:
      Skip waiting for WAL persistence on write.
    • acceptPartialSafe

      public boolean acceptPartialSafe(@Nonnull ClientConfig config)
      Parameters:
      config - with default value
      Returns:
      Accept partial write.
    • useV2ApiSafe

      public boolean useV2ApiSafe(@Nonnull ClientConfig config)
      Parameters:
      config - with default value
      Returns:
      Route writes to the V2 API endpoint.
    • validate

      public void validate(@Nonnull ClientConfig config)
      Validate write option combinations.
      Parameters:
      config - with default values
    • headersSafe

      @Nonnull public Map<String,String> headersSafe()
      Returns:
      The headers to be added to write request.
    • tagOrderSafe

      @Nonnull public List<String> tagOrderSafe()
      Returns:
      preferred order of tags in line protocol serialization.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object