Class WorkflowServiceStubsOptions.Builder
- java.lang.Object
-
- io.temporal.serviceclient.WorkflowServiceStubsOptions.Builder
-
- Enclosing class:
- WorkflowServiceStubsOptions
public static class WorkflowServiceStubsOptions.Builder extends java.lang.Object
Builder is the builder for ClientOptions.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description T
addGrpcClientInterceptor(io.grpc.ClientInterceptor grpcClientInterceptor)
T
addGrpcMetadataProvider(GrpcMetadataProvider grpcMetadataProvider)
WorkflowServiceStubsOptions
build()
Builds and returns a ClientOptions object.T
setChannel(io.grpc.ManagedChannel channel)
Sets fully custom user-configured gRPC channel to use.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.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.WorkflowServiceStubsOptions.Builder
setDisableHealthCheck(boolean disableHealthCheck)
Deprecated.Use more explicitWorkflowServiceStubs.newServiceStubs(WorkflowServiceStubsOptions)
that doesn't perform an explicit connection and health check.T
setEnableHttps(boolean enableHttps)
Sets option to enable SSL/TLS/HTTPS for gRPC.T
setEnableKeepAlive(boolean enableKeepAlive)
Enables keep alive ping from client to the server, which can help drop abruptly closed connections faster.T
setGrpcClientInterceptors(java.util.Collection<io.grpc.ClientInterceptor> grpcClientInterceptors)
T
setGrpcMetadataProviders(java.util.Collection<GrpcMetadataProvider> grpcMetadataProviders)
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.T
setHeaders(io.grpc.Metadata headers)
T
setHealthCheckAttemptTimeout(java.time.Duration healthCheckAttemptTimeout)
Deprecated.rpcTimeout
is now used as an attempt timeout.T
setHealthCheckTimeout(java.time.Duration healthCheckTimeout)
Deprecated.Use more explicitWorkflowServiceStubs.newConnectedServiceStubs(WorkflowServiceStubsOptions, Duration)
with a timeout parameter insteadT
setKeepAlivePermitWithoutStream(boolean keepAlivePermitWithoutStream)
If true, client sends keepalive pings even with no active RPCs.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.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.T
setMetricsScope(com.uber.m3.tally.Scope metricsScope)
Sets the scope to be used for metrics reporting.WorkflowServiceStubsOptions.Builder
setQueryRpcTimeout(java.time.Duration timeout)
Deprecated.WorkflowServiceStubsOptions.Builder
setRpcLongPollTimeout(java.time.Duration timeout)
Sets the rpc timeout value for the following long poll based operations: PollWorkflowTaskQueue, PollActivityTaskQueue, GetWorkflowExecutionHistory.WorkflowServiceStubsOptions.Builder
setRpcQueryTimeout(java.time.Duration rpcQueryTimeout)
Sets the rpc timeout value for query calls.WorkflowServiceStubsOptions.Builder
setRpcRetryOptions(RpcRetryOptions rpcRetryOptions)
Allows customization of retry options for the outgoing RPC calls to temporal service.WorkflowServiceStubsOptions.Builder
setRpcTimeout(java.time.Duration timeout)
Sets the rpc timeout value for non-query and non-long-poll calls.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.T
setTarget(java.lang.String target)
Sets a target string, which can be either a validNameResolver
-compliant URI, or an authority string.WorkflowServiceStubsOptions
validateAndBuildWithDefaults()
-
-
-
Method Detail
-
setDisableHealthCheck
@Deprecated public WorkflowServiceStubsOptions.Builder setDisableHealthCheck(boolean disableHealthCheck)
Deprecated.Use more explicitWorkflowServiceStubs.newServiceStubs(WorkflowServiceStubsOptions)
that doesn't perform an explicit connection and health check.If false, enables client to make a request to health check endpoint to make sure that the server is accessible.
-
setRpcTimeout
public WorkflowServiceStubsOptions.Builder setRpcTimeout(java.time.Duration timeout)
Sets the rpc timeout value for non-query and non-long-poll calls. Default is 10 seconds.This timeout is applied to only a single rpc server call, not a complete client-server interaction. In case of failure, the requests are automatically retried according to
setRpcRetryOptions(RpcRetryOptions)
. The full interaction is limited byRpcRetryOptions.Builder.setExpiration(Duration)
orRpcRetryOptions.Builder.setMaximumAttempts(int)
}, whichever happens first.For example, let's consider you've called
WorkflowClient#start
, and this timeout is set to 10s, whileRpcRetryOptions.Builder.setExpiration(Duration)
is set to 60s, and the server is responding slowly. The first two RPC calls may time out and be retried, but if the third one completes fast, the overallWorkflowClient#start
call will successfully resolve.- Returns:
this
-
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.
-
setRpcQueryTimeout
public WorkflowServiceStubsOptions.Builder setRpcQueryTimeout(java.time.Duration rpcQueryTimeout)
Sets the rpc timeout value for query calls. Default is 10 seconds.This timeout is applied to only a single rpc server call, not a complete client-server interaction. In case of failure, the requests are automatically retried according to
setRpcRetryOptions(RpcRetryOptions)
. The full interaction is limited byRpcRetryOptions.Builder.setExpiration(Duration)
orRpcRetryOptions.Builder.setMaximumAttempts(int)
}, whichever happens first.For example, let's consider you've called
WorkflowStub#query
, and this timeout is set to 10s, whileRpcRetryOptions.Builder.setExpiration(Duration)
is set to 60s, and the server is responding slowly or the query is not getting picked up by the worker for any reason. The first two RPC calls may time out and be retried, but if the third one completes fast, the overallWorkflowStub#query
call will successfully resolve.
-
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)
-
setQueryRpcTimeout
public WorkflowServiceStubsOptions.Builder setQueryRpcTimeout(java.time.Duration timeout)
Deprecated.Sets the rpc timeout value for query calls. Default is 10 seconds.- Parameters:
timeout
- timeout.
-
build
public WorkflowServiceStubsOptions build()
Builds and returns a ClientOptions object.- Returns:
- ClientOptions object with the specified params.
-
validateAndBuildWithDefaults
public WorkflowServiceStubsOptions validateAndBuildWithDefaults()
-
setTarget
public T setTarget(java.lang.String target)
Sets a target string, which can be either a validNameResolver
-compliant URI, or an authority string. SeeManagedChannelBuilder.forTarget(String)
for more information about parameter format. Default isDEFAULT_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 useNettyChannelBuilder
to create aManagedChannel
.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 withServiceStubsOptions.Builder.setTarget(String)
. The listener is called with an instance ofNettyChannelBuilder
that will be used by Temporal Stubs to create aManagedChannel
. 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 ofWorkflowServiceStubsOptions.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)
andsetConnectionBackoffResetFrequency(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 usingSimpleSslContextBuilder
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
ifsetSslContext(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
-
setHealthCheckTimeout
@Deprecated public T setHealthCheckTimeout(java.time.Duration healthCheckTimeout)
Deprecated.Use more explicitWorkflowServiceStubs.newConnectedServiceStubs(WorkflowServiceStubsOptions, Duration)
with a timeout parameter insteadSet a HealthCheckTimeout after which to stop waiting while checking server connection when creating new client.- 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
-
-