Class WorkflowServiceStubsOptions.Builder

  • Enclosing class:
    WorkflowServiceStubsOptions

    public static class WorkflowServiceStubsOptions.Builder
    extends java.lang.Object
    Builder is the builder for ClientOptions.
    • Method Detail

      • setRpcLongPollTimeout

        public WorkflowServiceStubsOptions.Builder setRpcLongPollTimeout​(java.time.Duration timeout)
        Sets the rpc timeout value for the following long poll based operations: PollWorkflowTaskQueue, PollActivityTaskQueue, GetWorkflowExecutionHistory. Defaults to 70 seconds.

        Server always responds below this timeout. Most users should never modify the default value of 70s. The only reasonable reason to modify this timeout it if there is a reversed proxy in the network that cuts the gRPC requests really short and there is no way to adjust it.

      • setRpcRetryOptions

        public WorkflowServiceStubsOptions.Builder setRpcRetryOptions​(RpcRetryOptions rpcRetryOptions)
        Allows customization of retry options for the outgoing RPC calls to temporal service.

        Note that default values should be reasonable for most users, be cautious when changing these values as it may result in increased load to the temporal backend or bad network instability tolerance.

        Defaults are:

        • Retries are limited by the maximum period of 1 minute
        • Initial period between retries: 50ms
        • Exponential Backoff Coefficient (exponential rate) for the retry period is 2
        See Also:
        Backoff Calculator to get a grasp on an Exponential Backoff as a retry strategy, setRpcTimeout(Duration), setRpcQueryTimeout(Duration)
      • build

        public WorkflowServiceStubsOptions build()
        Builds and returns a ClientOptions object.
        Returns:
        ClientOptions object with the specified params.
      • setTarget

        public T setTarget​(java.lang.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 DEFAULT_LOCAL_DOCKER_TARGET

        Mutually exclusive with setChannel(ManagedChannel).

        Returns:
        this
      • setChannelInitializer

        public T setChannelInitializer​(java.util.function.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 ServiceStubsOptions.Builder.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
      • 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​(java.time.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​(java.time.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
      • setGrpcMetadataProviders

        public T setGrpcMetadataProviders​(java.util.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​(java.util.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
      • setHealthCheckAttemptTimeout

        @Deprecated
        public T setHealthCheckAttemptTimeout​(java.time.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
      • setEnableKeepAlive

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

        public T setKeepAliveTime​(java.time.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.
        Returns:
        this
      • setKeepAliveTimeout

        public T setKeepAliveTimeout​(java.time.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.
        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
        Returns:
        this