temporal_sdk_client (temporal_sdk v0.1.15)
View SourceSDK gRPC client module.
SDK gRPC client is a supervised gRPC connections pool that connects to the Temporal server Frontend Service gRPC service handler port (default 7233). Each SDK cluster owns its individual SDK gRPC client.
SDK gRPC Client Configuration
adapter - temporal_sdk_grpc:adapter/0 configuration of the HTTP/2 adapter used to handle
gRPC requests. Default: {temporal_sdk_grpc_adapter_gun, []}.
pool_size - gRPC client connection pool size.
When increasing the connection pool size, also consider increasing the OS file descriptor (FD) limits.
Default: 10.
pool_strategy - gRPC client connection pool strategy, one of: round_robin or random.
Default: round_robin.
grpc_opts - temporal_sdk_grpc:opts/0 gRPC request options for all gRPC requests except
long-poll gRPC requests.
Default:
[
{converter,
{temporal_sdk_proto_converter, {
%% default global payload codecs:
[
temporal_sdk_codec_payload_binary,
temporal_sdk_codec_payload_json,
temporal_sdk_codec_payload_erl
],
%% custom payload codecs defined per messages list:
[
{
%% failure codecs
[
temporal_sdk_codec_payload_text
],
%% failure messages
[
'temporal.api.failure.v1.ApplicationFailureInfo',
'temporal.api.failure.v1.CanceledFailureInfo',
'temporal.api.failure.v1.ResetWorkflowFailureInfo',
'temporal.api.failure.v1.TimeoutFailureInfo'
]
}
]
}}},
{codec, {temporal_sdk_codec_binaries, [], []}},
{compressor, {temporal_sdk_grpc_compressor_identity, [], []}},
{interceptor, {temporal_sdk_grpc_interceptor_identity, [], []}},
{headers, #{
<<"te">> => <<"trailers">>,
<<"user-agent">> => temporal_sdk_utils:worker_version()
}},
{timeout, 5_000},
{retry_policy, #{
max_attempts => 3,
backoff_coefficient => 2,
initial_interval => 100,
maximum_interval => 1_000,
is_retryable => fun temporal_sdk_api:is_retryable/3
}},
{maximum_request_size, 4_100_000}
]grpc_opts_longpoll - temporal_sdk_grpc:opts/0 overwrites for gRPC long-poll request options.
Long-poll gRPC request options are evaluated by merging overwrites defined here with the values
provided in the grpc_opts.
Temporal gRPC long-poll requests:
PollActivityTaskQueue,PollWorkflowTaskQueue,PollNexusTaskQueue.
Default:
[
{timeout, 70_000},
{retry_policy, disabled}
]helpers - gRPC request helpers.
See gRPC Helpers section below for details.
Default:
[
{id, fun temporal_sdk_api:id/4},
{identity, fun temporal_sdk_api:identity/3},
{to_payload_mapper, fun temporal_sdk_api:to_payload_mapper/5},
{from_payload_mapper, fun temporal_sdk_api:from_payload_mapper/5},
{serializer, fun temporal_sdk_api:serializer/4}
]gRPC Helpers
SDK gRPC client gRPC helpers functions must be implemented as non-raising and non-blocking functions. Violating this requirement will cause SDK failures or unexpected behavior.
id - temporal_sdk_client:helpers_id_fun/0 function used to generate Temporal API gRPC request
identifiers.
See temporal_sdk_api:id/4 for the default SDK implementation.
identity - temporal_sdk_client:helpers_identity_fun/0 function used to generate Temporal API
gRPC request worker or client identities.
See temporal_sdk_api:identity/3 for the default SDK implementation.
to_payload_mapper - temporal_sdk_client:to_payload_mapper/0 function mapping from Erlang term
temporal_sdk:term_to_payload/0 to Temporal payload temporal_sdk:temporal_payload/0.
See temporal_sdk_api:to_payload_mapper/5 for the default SDK implementation.
from_payload_mapper - temporal_sdk_client:from_payload_mapper/0 function mapping from
Temporal payload temporal_sdk:temporal_payload/0 to Erlang term
temporal_sdk:term_from_payload/0.
See temporal_sdk_api:from_payload_mapper/5 for the default SDK implementation.
serializer - temporal_sdk_client:helpers_serializer_fun/0 function used to serialize
Erlang terms to Unicode characters before sending them to the Temporal server.
See temporal_sdk_api:serializer/4 for the default SDK implementation.
Summary
Types
gRPC call request succesfull or failed response result.
gRPC call request failed response result.
gRPC call request succesfull response result.
gRPC cast request return result.
SDK gRPC client helper function mapping from Temporal payload to Erlang term.
gRPC request options.
SDK gRPC client request processing helper functions.
Function generating gRPC request identifiers.
Function generating gRPC request worker/client identities.
Function serializing Erlang terms to Unicode characters.
Temporal API gRPC service message type specification.
Temporal API gRPC service message name.
gRPC msg request return result.
SDK gRPC client configuration options as a map.
gRPC request common error.
gRPC request type.
gRPC request response result or return result.
SDK gRPC client helper function mapping Erlang term to Temporal payload.
SDK gRPC client configuration options as a property list.
Types
-type call_result() :: call_result_success() | call_result_error().
gRPC call request succesfull or failed response result.
-type call_result_error() :: temporal_sdk_grpc:result_error() | request_error().
gRPC call request failed response result.
-type call_result_success() :: {ok, dynamic()}.
gRPC call request succesfull response result.
-type cast_result() :: ok | request_error().
gRPC cast request return result.
-type from_payload_mapper() :: fun((Cluster :: temporal_sdk_cluster:cluster_name(), MsgName :: msg_name(), Key :: term(), Position :: pos_integer(), Data :: temporal_sdk:temporal_payload()) -> Arg :: temporal_sdk:term_from_payload()).
SDK gRPC client helper function mapping from Temporal payload to Erlang term.
-type grpc_opts() :: temporal_sdk_grpc:opts().
gRPC request options.
-type helpers() :: #{id => helpers_id_fun(), identity => helpers_identity_fun(), to_payload_mapper => to_payload_mapper(), from_payload_mapper => from_payload_mapper(), serializer => helpers_serializer_fun()}.
SDK gRPC client request processing helper functions.
-type helpers_id_fun() :: fun((Cluster :: temporal_sdk_cluster:cluster_name(), MsgName :: msg_name(), IdKey :: term(), Msg :: map()) -> unicode:chardata()).
Function generating gRPC request identifiers.
-type helpers_identity_fun() :: fun((Cluster :: temporal_sdk_cluster:cluster_name(), Id :: temporal_sdk:serializable(), MsgName :: msg_name()) -> unicode:chardata()).
Function generating gRPC request worker/client identities.
-type helpers_serializer_fun() :: fun((Cluster :: temporal_sdk_cluster:cluster_name(), MsgName :: temporal_sdk_client:msg_name() | 'temporal.api.command.v1.*' | atom(), Key :: term(), Term :: temporal_sdk:serializable()) -> unicode:chardata()).
Function serializing Erlang terms to Unicode characters.
-type msg() :: temporal_sdk_proto_service_workflow_binaries:'$msg'() | temporal_sdk_proto_service_operator_binaries:'$msg'().
Temporal API gRPC service message type specification.
-type msg_name() :: temporal_sdk_proto_service_workflow_binaries:'$msg_name'() | temporal_sdk_proto_service_operator_binaries:'$msg_name'().
Temporal API gRPC service message name.
-type msg_result() :: reference() | request_error().
gRPC msg request return result.
-type opts() :: #{adapter => temporal_sdk_grpc:adapter(), pool_size => pos_integer(), pool_strategy => round_robin | random, grpc_opts => grpc_opts(), grpc_opts_longpoll => grpc_opts(), helpers => helpers()}.
SDK gRPC client configuration options as a map.
-type request_error() :: {error, timeout | {invalid_opts, Details :: term()} | invalid_cluster | invalid_request_type}.
gRPC request common error.
-type request_type() :: call | cast | msg.
gRPC request type.
gRPC request types:
call- blocking request where response result is of typecall_result/0,cast- non-blocking "fire-and-forget" request where response is not returned,msg- asynchronous request where response result is received as an OTP message.
-type result() :: call_result() | cast_result() | msg_result().
gRPC request response result or return result.
-type to_payload_mapper() :: fun((Cluster :: temporal_sdk_cluster:cluster_name(), MsgName :: msg_name(), Key :: term(), Position :: pos_integer(), Data :: temporal_sdk:term_to_payload()) -> Payload :: temporal_sdk:temporal_payload()).
SDK gRPC client helper function mapping Erlang term to Temporal payload.
-type user_opts() :: [{adapter, temporal_sdk_grpc:adapter()} | {pool_size, pos_integer()} | {pool_strategy, round_robin | random} | {grpc_opts, grpc_opts()} | {grpc_opts_longpoll, grpc_opts()} | {helpers, helpers()}].
SDK gRPC client configuration options as a property list.