pip_services3_rpc.clients package
Submodules
Module contents
pip_services3_rpc.clients.__init__
Clients module initialization
- copyright
Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.
- license
MIT, see LICENSE for more details.
- class pip_services3_rpc.clients.CommandableHttpClient(base_route: str)
Bases:
pip_services3_rpc.clients.RestClient.RestClient
,abc.ABC
Abstract client that calls commandable HTTP service. Commandable services are generated automatically for ICommandable objects. Each command is exposed as POST operation that receives all parameters in body object.
- ### Configuration parameters ###
base_route: base route for remote URI
- connection(s):
discovery_key: (optional) a key to retrieve the connection from IDiscovery
protocol: connection protocol: http or https
host: host name or IP address
port: port number
uri: resource URI or connection string with all parameters in it
- options:
retries: number of retries (default: 3)
connect_timeout: connection timeout in milliseconds (default: 10 sec)
timeout: invocation timeout in milliseconds (default: 10 sec)
- ### References ###
*:logger:*:*:1.0 (optional)
ILogger
components to pass log messages*:counters:*:*:1.0 (optional)
ICounters
components to pass collected measurements*:discovery:*:*:1.0 (optional)
IDiscovery
services to resolve connection
Example:
class MyCommandableHttpClient(CommandableHttpClient, IMyClient): # ... def get_data(self, correlation_id, id): return self.call_command("get_data", correlation_id, MyData(id)) # ... client = MyCommandableHttpClient() client.configure(ConfigParams.from_tuples("connection.protocol", "http", "connection.host", "localhost", "connection.port", 8080)) data = client.getData("123", "1") # ...
- call_command(name: str, correlation_id: Optional[str], params: Any) Any
Calls a remote method via HTTP commadable protocol. The call is made via POST operation and all parameters are sent in body object. The complete route to remote method is defined as baseRoute + “/” + name.
- Parameters
name – a name of the command to call.
correlation_id – (optional) transaction id to trace execution through call chain.
params – command parameters.
- Returns
result of the command.
- class pip_services3_rpc.clients.DirectClient
Bases:
pip_services3_commons.config.IConfigurable.IConfigurable
,pip_services3_commons.refer.IReferenceable.IReferenceable
,pip_services3_commons.run.IOpenable.IOpenable
Abstract client that calls controller directly in the same memory space. It is used when multiple microservices are deployed in a single container (monolyth) and communication between them can be done by direct calls rather then through the network.
- ### Configuration parameters ###
- dependencies:
controller: override controller descriptor
- ### References ###
*:logger:*:*:1.0 (optional)
ILogger
components to pass log messages*:counters:*:*:1.0 (optional)
ICounters
components to pass collected measurements*:controller:*:*:1.0 controller to call business methods
Example:
class MyDirectClient(DirectClient, IMyClient): def __init__(self): super(MyDirectClient, self).__init__() self._dependencyResolver.put('controller', Descriptor("mygroup", "controller", "*", "*", "*")) # ... def get_data(self, correlation_id, id): timing = self.instrument(correlationId, 'myclient.get_data') result = self._controller.get_data(correlationId, id) timing.end_timing() return result client = MyDirectClient() client.set_references(References.from_tuples(Descriptor("mygroup","controller","default","default","1.0"), controller)) data = client.get_data("123", "1") # ...
- close(correlation_id: Optional[str])
Closes component and frees used resources.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
- configure(config: pip_services3_commons.config.ConfigParams.ConfigParams)
Configures component by passing configuration parameters.
- Parameters
config – configuration parameters to be set.
- is_open() bool
Checks if the component is opened.
- Returns
true if the component has been opened and false otherwise.
- open(correlation_id: Optional[str])
Opens the component.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
- set_references(references: pip_services3_commons.refer.IReferences.IReferences)
Sets references to dependent components.
- Parameters
references – references to locate the component dependencies.
- class pip_services3_rpc.clients.RestClient
Bases:
pip_services3_commons.run.IOpenable.IOpenable
,pip_services3_commons.config.IConfigurable.IConfigurable
,pip_services3_commons.refer.IReferenceable.IReferenceable
Abstract client that calls remove endpoints using HTTP/REST protocol.
- ### Configuration parameters ###
base_route: base route for remote URI
- connection(s):
discovery_key: (optional) a key to retrieve the connection from
IDiscovery
protocol: connection protocol: http or https
host: host name or IP address
port: port number
uri: resource URI or connection string with all parameters in it
- options:
retries: number of retries (default: 3)
connect_timeout: connection timeout in milliseconds (default: 10 sec)
timeout: invocation timeout in milliseconds (default: 10 sec)
- ### References ###
*:logger:*:*:1.0 (optional)
ILogger
components to pass log messages*:counters:*:*:1.0 (optional)
ICounters
components to pass collected measurements*:discovery:*:*:1.0 (optional)
IDiscovery
services to resolve connection
Example:
class MyRestClient(RestClient, IMyClient): def get_data(self, correlation_id, id): timing = self.instrument(correlationId, 'myclient.get_data') result = self._controller.get_data(correlationId, id) timing.end_timing() return result # ... client = MyRestClient() client.configure(ConfigParams.fromTuples("connection.protocol", "http", "connection.host", "localhost", "connection.port", 8080)) data = client.getData("123", "1") # ...
- add_correlation_id(params: Optional[Any] = None, correlation_id: Optional[str] = None) Any
Adds a correlation id (correlation_id) to invocation parameter map.
- Parameters
params – invocation parameters.
correlation_id – (optional) a correlation id to be added.
- Returns
invocation parameters with added correlation id.
- close(correlation_id: Optional[str])
Closes component and frees used resources.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
- configure(config: pip_services3_commons.config.ConfigParams.ConfigParams)
Configures component by passing configuration parameters.
- Parameters
config – configuration parameters to be set.
- fix_route(route) str
- is_open() bool
Checks if the component is opened.
- Returns
true if the component has been opened and false otherwise.
- open(correlation_id: Optional[str])
Opens the component.
- Parameters
correlation_id – (optional) transaction id to trace execution through call chain.
- set_references(references: pip_services3_commons.refer.IReferences.IReferences)
Sets references to dependent components.
- Parameters
references – references to locate the component dependencies.