Class ServiceStubsOptions.Builder<T extends ServiceStubsOptions.Builder<T>>

java.lang.Object
io.temporal.serviceclient.ServiceStubsOptions.Builder<T>
Direct Known Subclasses:
CloudServiceStubsOptions.Builder, OperatorServiceStubsOptions.Builder, WorkflowServiceStubsOptions.Builder
Enclosing class:
ServiceStubsOptions

public static class ServiceStubsOptions.Builder<T extends ServiceStubsOptions.Builder<T>> extends Object
  • Constructor Details

  • Method Details

    • setTarget

      public T setTarget(String target)
      Sets a target string, which can be either a valid NameResolver-compliant URI, or an authority string. See ManagedChannelBuilder.forTarget(String) for more information about parameter format. Default is ServiceStubsOptions.DEFAULT_LOCAL_DOCKER_TARGET

      Mutually exclusive with setChannel(ManagedChannel).

      Returns:
      this
    • setChannelInitializer

      public T setChannelInitializer(Consumer<io.grpc.ManagedChannelBuilder<?>> channelInitializer)
      Gives an opportunity to provide some additional configuration to the channel builder or override configurations done by the Temporal Stubs. Currently, Temporal Stubs use NettyChannelBuilder to create a ManagedChannel.

      Advanced API

      Mutually exclusive with setChannel(ManagedChannel).

      Parameters:
      channelInitializer - listener that will be called as a last step of channel creation if Stubs are configured with setTarget(String). The listener is called with an instance of NettyChannelBuilder that will be used by Temporal Stubs to create a ManagedChannel. The builder type may change in the future.
      Returns:
      this
    • setChannel

      public T setChannel(io.grpc.ManagedChannel channel)
      Sets fully custom user-configured gRPC channel to use.

      Before supplying a fully custom channel using this method, it's recommended to first consider using setTarget(String) + other options of WorkflowServiceStubsOptions.Builder + setChannelInitializer(Consumer) for some rarely used configuration.
      This option is not intended for the majority of users as it disables some Temporal connection management features and can lead to outages if the channel is configured or managed improperly.

      Mutually exclusive with setTarget(String), setChannelInitializer(Consumer), setSslContext(SslContext), setGrpcReconnectFrequency(Duration) and setConnectionBackoffResetFrequency(Duration). These options are ignored if the custom channel is supplied.

      Returns:
      this
    • setSslContext

      public T setSslContext(io.grpc.netty.shaded.io.netty.handler.ssl.SslContext sslContext)
      Sets gRPC SSL Context to use, used for more advanced scenarios such as mTLS. Supersedes enableHttps; Exclusive with channel. Consider using SimpleSslContextBuilder which greatly simplifies creation of the TLS enabled SslContext with client and server key validation.
      Returns:
      this
    • setEnableHttps

      public T setEnableHttps(boolean enableHttps)
      Sets option to enable SSL/TLS/HTTPS for gRPC.

      Mutually exclusive with channel; Ignored and assumed true if setSslContext(SslContext) is specified.

      Returns:
      this
    • setConnectionBackoffResetFrequency

      public T setConnectionBackoffResetFrequency(Duration connectionBackoffResetFrequency)
      Sets frequency at which gRPC connection backoff should be reset practically defining an upper limit for the maximum backoff duration. If set to null then no backoff reset will be performed and we'll rely on default gRPC backoff behavior defined in ExponentialBackoffPolicy.

      Mutually exclusive with setChannel(ManagedChannel).

      Parameters:
      connectionBackoffResetFrequency - frequency, defaults to once every 10 seconds. Set to null in order to disable this feature
      Returns:
      this
      See Also:
      • ManagedChannel.resetConnectBackoff()
    • setGrpcReconnectFrequency

      public T setGrpcReconnectFrequency(Duration grpcReconnectFrequency)
      Sets frequency at which gRPC channel will be moved into an idle state and triggers tear-down of the channel's name resolver and load balancer, while still allowing on-going RPCs on the channel to continue. New RPCs on the channel will trigger creation of a new connection. This allows worker to connect to a new temporal backend host periodically avoiding hot spots and resulting in a more even connection distribution.

      Mutually exclusive with setChannel(ManagedChannel).

      Parameters:
      grpcReconnectFrequency - frequency, defaults to once every 1 minute. Set to null in order to disable this feature
      Returns:
      this
      See Also:
      • ManagedChannel.enterIdle()
    • setHeaders

      public T setHeaders(io.grpc.Metadata headers)
      Parameters:
      headers - gRPC headers to be added to every call
      Returns:
      this
    • addGrpcMetadataProvider

      public T addGrpcMetadataProvider(GrpcMetadataProvider grpcMetadataProvider)
      Parameters:
      grpcMetadataProvider - gRPC metadata/headers provider to be called on each gRPC request to supply additional headers
      Returns:
      this
    • addApiKey

      public T addApiKey(AuthorizationTokenSupplier apiKey)
      Add a AuthorizationGrpcMetadataProvider to the gRPC metadata providers that supplies an authentication token on each gRPC request.
      Parameters:
      apiKey - authentication token supplier to be called on each gRPC request. SDK will automatically add the "Bearer " prefix.
      Returns:
      this
    • setGrpcMetadataProviders

      public T setGrpcMetadataProviders(Collection<GrpcMetadataProvider> grpcMetadataProviders)
      Parameters:
      grpcMetadataProviders - gRPC metadata/headers providers to be called on each gRPC request to supply additional headers
      Returns:
      this
    • addGrpcClientInterceptor

      public T addGrpcClientInterceptor(io.grpc.ClientInterceptor grpcClientInterceptor)
      Parameters:
      grpcClientInterceptor - gRPC client interceptor to be added to gRPC channel
      Returns:
      this
    • setGrpcClientInterceptors

      public T setGrpcClientInterceptors(Collection<io.grpc.ClientInterceptor> grpcClientInterceptors)
      Parameters:
      grpcClientInterceptors - gRPC client interceptors to be added to gRPC channel
      Returns:
      this
    • setMetricsScope

      public T setMetricsScope(com.uber.m3.tally.Scope metricsScope)
      Sets the scope to be used for metrics reporting. Optional. Default is to not report metrics.

      This method should be used to integrate client and workers with external metrics and monitoring systems.

      Example:

      
       PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
       StatsReporter reporter = new MicrometerClientStatsReporter(registry);
       Scope scope = new RootScopeBuilder().reporter(reporter).reportEvery(Duration.ofSeconds(10));
       WorkflowServiceStubsOptions options =
           WorkflowServiceStubsOptions.newBuilder()
               .setMetricsScope(scope)
               .build();
       

      Note: Don't mock Scope in tests! If you need to verify the metrics behavior, create a real Scope and mock, stub or spy a reporter instance:

      
       StatsReporter reporter = mock(StatsReporter.class);
       Scope metricsScope =
           new RootScopeBuilder()
               .reporter(reporter)
               .reportEvery(com.uber.m3.util.Duration.ofMillis(10));
       
      Parameters:
      metricsScope - the scope to be used for metrics reporting.
      Returns:
      this
    • setGrpcCompression

      public T setGrpcCompression(GrpcCompression grpcCompression)
      Sets outbound transport-level gRPC compression. Defaults to GrpcCompression.GZIP. If a specific server RPC does not support gzip, the SDK may retry that RPC without compression and continue using gzip for other RPCs. Set to GrpcCompression.NONE to opt out of compressing requests.

      The SDK uses the default gRPC response decompression registry for all compression options, so disabling request compression does not disable accepting compressed responses.

      Returns:
      this
    • setHealthCheckAttemptTimeout

      @Deprecated public T setHealthCheckAttemptTimeout(Duration healthCheckAttemptTimeout)
      Deprecated.
      rpcTimeout is now used as an attempt timeout.
      Set the time to wait between service responses on each health check.
      Returns:
      this
    • setHealthCheckTimeout

      @Deprecated public T setHealthCheckTimeout(Duration healthCheckTimeout)
      Deprecated.
      Set a HealthCheckTimeout after which to stop waiting while checking server connection when creating new client.
      Returns:
      this
    • setSystemInfoTimeout

      public T setSystemInfoTimeout(Duration systemInfoTimeout)
      Set a SystemInfoTimeout that specifies how long the client tries to fetch server capabilities.
      Returns:
      this
    • setEnableKeepAlive

      public T setEnableKeepAlive(boolean enableKeepAlive)
      Enables keep alive ping from client to the server, which can help drop abruptly closed connections faster.

      Default is true

      Returns:
      this
    • setKeepAliveTime

      public T setKeepAliveTime(Duration keepAliveTime)
      After a duration of this time if the client doesn't see any activity it pings the server to see if the transport is still alive. If set below 10s, a minimum value of 10s will be used instead.

      Default is 30s

      Returns:
      this
    • setKeepAliveTimeout

      public T setKeepAliveTimeout(Duration keepAliveTimeout)
      After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that the connection is closed.

      Default is 15s

      Returns:
      this
    • setKeepAlivePermitWithoutStream

      public T setKeepAlivePermitWithoutStream(boolean keepAlivePermitWithoutStream)
      If true, client sends keepalive pings even with no active RPCs. If false, when there are no active RPCs, Time and Timeout will be ignored and no keepalive pings will be sent. * @return

      Default is true

      Returns:
      this
    • setRpcTimeout

      public T setRpcTimeout(Duration timeout)
      Sets the rpc timeout value. Default is 10 seconds.
      Returns:
      this
    • build

      public ServiceStubsOptions build()
      Returns:
      Built ServiceStubOptions object with the specified params
    • validateAndBuildWithDefaults

      public ServiceStubsOptions validateAndBuildWithDefaults()