pip_services3_rpc.clients.DirectClient module
pip_services3_rpc.client.DirectClient
Direct client implementation
- copyright
Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.
- license
MIT, see LICENSE for more details.
- class pip_services3_rpc.clients.DirectClient.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.