DirectClient<T> class
abstract
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.
getter/setter pair
- counters ↔ CompositeCounters
-
The performance counters
getter/setter pair
- dependencyResolver ↔ DependencyResolver
-
The dependency resolver to get controller reference.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- logger ↔ CompositeLogger
-
The logger.
getter/setter pair
- opened ↔ bool
-
The open flag.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- tracer ↔ CompositeTracer
-
The tracer.
getter/setter pair
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) → InstrumentTiming - 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.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
open(
String? correlationId) → Future - Opens the component.
-
setReferences(
IReferences references) → void - Sets references to dependent components.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited