DirectClient<T> class
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 extends DirectClient<IMyController> implements IMyClient {
public MyDirectClient(): super() {
dependencyResolver.put('controller', Descriptor(
"mygroup", "controller", "*", "*", "*"));
}
...
Future<MyData> getData(String correlationId, String id) async {
var timing = instrument(correlationId, 'myclient.get_data');
try {
var result = await controller.getData(correlationId, id)
timing.endTiming();
return result;
} catch (err){
timing.endTiming();
instrumentError(correlationId, 'myclient.get_data', err, reerror=true);
});
}
...
}
var client = MyDirectClient();
client.setReferences(References.fromTuples([
Descriptor("mygroup","controller","default","default","1.0"), controller
]));
var result = await client.getData("123", "1")
...
Constructors
- DirectClient()
- Creates a new instance of the client.
Properties
- controller ↔ T
-
The controller reference.
read / write
- counters ↔ CompositeCounters
-
The performance counters
read / write
- dependencyResolver ↔ DependencyResolver
-
The dependency resolver to get controller reference.
read / write
- logger ↔ CompositeLogger
-
The logger.
read / write
- opened ↔ bool
-
The open flag.
read / write
- hashCode → int
-
The hash code for this object. [...]
read-only, inherited
- runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Methods
-
close(
String correlationId) → Future - Closes component and frees used resources. [...]
-
configure(
ConfigParams config) → void - Configures component by passing configuration parameters. [...]
-
instrument(
String correlationId String name) → Timing - Adds instrumentation to log calls and measure call time. It returns a Timing object that is used to end the time measurement. [...]
-
instrumentError(
String correlationId, String name, dynamic err, [ bool reerror = false ]) → void - Adds instrumentation to error handling. [...]
-
isOpen(
) → bool - Checks if the component is opened. [...]
-
open(
String correlationId) → Future - Opens the component. [...]
-
setReferences(
IReferences references) → void - Sets references to dependent components. [...]
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed. [...]
inherited
-
toString(
) → String -
Returns a string representation of this object.
inherited
Operators
-
operator ==(
dynamic other) → bool -
The equality operator. [...]
inherited