DirectClient<T> class
abstract
Abstract client that calls service 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
:- service: override service descriptor
References
\*:logger:\*:\*:1.0
(optional) ILogger components to pass log messages\*:counters:\*:\*:1.0
(optional) ICounters components to pass collected measurements\*:tracer:\*:\*:1.0
(optional) ITracer components to record traces\*:service:\*:\*:1.0
service to call business methods
Example
class MyDirectClient extends DirectClient<IMyService> implements IMyClient {
public MyDirectClient(): super() {
dependencyResolver.put('service', Descriptor(
"mygroup", "service", "*", "*", "*"));
}
...
Future<MyData> getData(IContext? context, String id) async {
var timing = instrument(context, 'myclient.get_data');
try {
var result = await service.getData(context, id)
timing.endTiming();
return result;
} catch (err){
timing.endTiming();
instrumentError(context, 'myclient.get_data', err, reerror=true);
});
}
...
}
var client = MyDirectClient();
client.setReferences(References.fromTuples([
Descriptor("mygroup","service","default","default","1.0"), service
]));
var result = await client.getData("123", "1")
...
- Implemented types
Constructors
- DirectClient()
- Creates a new instance of the client.
Properties
- counters ↔ CompositeCounters
-
The performance counters
read / write
- dependencyResolver ↔ DependencyResolver
-
The dependency resolver to get service reference.
read / write
- hashCode → int
-
The hash code for this object.
read-onlyinherited
- logger ↔ CompositeLogger
-
The logger.
read / write
- opened ↔ bool
-
The open flag.
read / write
- runtimeType → Type
-
A representation of the runtime type of the object.
read-onlyinherited
- service ↔ T
-
The service reference.
read / write
- tracer ↔ CompositeTracer
-
The tracer.
read / write
Methods
-
close(
IContext? context) → Future -
Closes component and frees used resources.
override
-
configure(
ConfigParams config) → void -
Configures component by passing configuration parameters.
override
-
instrument(
IContext? context, 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(
IContext? context, String name, dynamic err, [bool? reerror = false]) → void - Adds instrumentation to error handling.
-
isOpen(
) → bool -
Checks if the component is opened.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
open(
IContext? context) → Future -
Opens the component.
override
-
setReferences(
IReferences references) → void -
Sets references to dependent components.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited