Class: Temporalio::Client::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/temporalio/client/connection.rb,
lib/temporalio/client/connection/service.rb,
lib/temporalio/client/connection/cloud_service.rb,
lib/temporalio/client/connection/operator_service.rb,
lib/temporalio/client/connection/workflow_service.rb

Overview

Connection to Temporal server that is not namespace specific. Most users will use connect instead of this directly.

Defined Under Namespace

Classes: CloudService, HTTPConnectProxyOptions, KeepAliveOptions, OperatorService, Options, RPCRetryOptions, Service, TLSOptions, WorkflowService

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_host:, api_key: nil, tls: false, rpc_metadata: {}, rpc_retry: RPCRetryOptions.new, identity: "#{Process.pid}@#{Socket.gethostname}", keep_alive: KeepAliveOptions.new, http_connect_proxy: nil, runtime: Runtime.default, lazy_connect: false) ⇒ Connection

Connect to Temporal server. Most users will use Temporalio::Client.connect instead of this directly. Parameters here match Options returned from #options by intention so options can be dup’d, altered, splatted to create a new connection.

Parameters:

  • target_host (String)

    host:port for the Temporal server. For local development, this is often localhost:7233.

  • api_key (String, nil) (defaults to: nil)

    API key for Temporal. This becomes the Authorization HTTP header with “Bearer ” prepended. This is only set if RPC metadata doesn’t already have an authorization key.

  • tls (Boolean, TLSOptions) (defaults to: false)

    If false, do not use TLS. If true, use system default TLS options. If TLS options are present, those TLS options will be used.

  • rpc_metadata (Hash<String, String>) (defaults to: {})

    Headers to use for all calls to the server. Keys here can be overriden by per-call RPC metadata keys.

  • rpc_retry (RPCRetryOptions) (defaults to: RPCRetryOptions.new)

    Retry options for direct service calls (when opted in) or all high-level calls made by this client (which all opt-in to retries by default).

  • identity (String) (defaults to: "#{Process.pid}@#{Socket.gethostname}")

    Identity for this client.

  • keep_alive (KeepAliveOptions) (defaults to: KeepAliveOptions.new)

    Keep-alive options for the client connection. Can be set to nil to disable.

  • http_connect_proxy (HTTPConnectProxyOptions, nil) (defaults to: nil)

    Options for HTTP CONNECT proxy.

  • runtime (Runtime) (defaults to: Runtime.default)

    Runtime for this client.

  • lazy_connect (Boolean) (defaults to: false)

    If true, there is no connection until the first call is attempted or a worker is created with it. Clients from lazy connections cannot be used for workers if they have not performed a connection.

See Also:



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/temporalio/client/connection.rb', line 159

def initialize(
  target_host:,
  api_key: nil,
  tls: false,
  rpc_metadata: {},
  rpc_retry: RPCRetryOptions.new,
  identity: "#{Process.pid}@#{Socket.gethostname}",
  keep_alive: KeepAliveOptions.new,
  http_connect_proxy: nil,
  runtime: Runtime.default,
  lazy_connect: false
)
  @options = Options.new(
    target_host:,
    api_key:,
    tls:,
    rpc_metadata:,
    rpc_retry:,
    identity:,
    keep_alive:,
    http_connect_proxy:,
    runtime:,
    lazy_connect:
  ).freeze
  # Create core client now if not lazy
  _core_client unless lazy_connect
  # Create service instances
  @workflow_service = WorkflowService.new(self)
  @operator_service = OperatorService.new(self)
  @cloud_service = CloudService.new(self)
end

Instance Attribute Details

#cloud_serviceCloudService (readonly)

Returns Raw gRPC cloud service.

Returns:



133
134
135
# File 'lib/temporalio/client/connection.rb', line 133

def cloud_service
  @cloud_service
end

#operator_serviceOperatorService (readonly)

Returns Raw gRPC operator service.

Returns:



130
131
132
# File 'lib/temporalio/client/connection.rb', line 130

def operator_service
  @operator_service
end

#optionsOptions (readonly)

Returns Frozen options for this client which has the same attributes as #initialize.

Returns:

  • (Options)

    Frozen options for this client which has the same attributes as #initialize.



124
125
126
# File 'lib/temporalio/client/connection.rb', line 124

def options
  @options
end

#workflow_serviceWorkflowService (readonly)

Returns Raw gRPC workflow service.

Returns:



127
128
129
# File 'lib/temporalio/client/connection.rb', line 127

def workflow_service
  @workflow_service
end

Instance Method Details

#connected?Boolean

Returns Whether this connection is connected. This is always ‘true` unless `lazy_connect` option was originally set, in which case this will be `false` until the first call is made.

Returns:

  • (Boolean)

    Whether this connection is connected. This is always ‘true` unless `lazy_connect` option was originally set, in which case this will be `false` until the first call is made.



203
204
205
# File 'lib/temporalio/client/connection.rb', line 203

def connected?
  !@core_client.nil?
end

#identityString

Returns Client identity.

Returns:

  • (String)

    Client identity.



197
198
199
# File 'lib/temporalio/client/connection.rb', line 197

def identity
  @options.identity
end

#target_hostString

Returns Target host this connection is connected to.

Returns:

  • (String)

    Target host this connection is connected to.



192
193
194
# File 'lib/temporalio/client/connection.rb', line 192

def target_host
  @options.target_host
end