@ti-engine/core 1.8.1 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/components/auditing.js +2 -4
- package/components/definitions.types.js +19 -4
- package/components/exchange/default/default-message-exchange.js +2 -0
- package/components/exchange/default/default-message-receiver.js +2 -0
- package/components/exchange/default/default-message-sender.js +2 -0
- package/components/exchange/message-dispatcher.js +4 -0
- package/components/exchange/message-exchange.js +4 -0
- package/components/exchange/message-handler.js +7 -5
- package/components/exchange/message-memory-cache.js +3 -0
- package/components/exchange/message-observer.js +2 -0
- package/components/exchange/message-receiver.js +2 -1
- package/components/exchange/message-sender.js +2 -2
- package/components/exchange/message-tracer.js +2 -3
- package/components/service-caller.js +2 -5
- package/components/service-consumer.js +2 -0
- package/components/service-executor.js +3 -5
- package/components/service-instance.js +2 -4
- package/components/service-provider.js +3 -0
- package/integrations/redis-integration.js +1 -5
- package/package.json +152 -36
- package/types/bin/start-instance.d.ts +1 -0
- package/types/components/auditing.d.ts +30 -0
- package/types/components/connection-observer.d.ts +49 -0
- package/types/components/definitions.types.d.ts +443 -0
- package/types/components/exchange/default/default-message-exchange.d.ts +61 -0
- package/types/components/exchange/default/default-message-receiver.d.ts +49 -0
- package/types/components/exchange/default/default-message-sender.d.ts +50 -0
- package/types/components/exchange/message-dispatcher.d.ts +77 -0
- package/types/components/exchange/message-exchange.d.ts +306 -0
- package/types/components/exchange/message-handler.d.ts +132 -0
- package/types/components/exchange/message-memory-cache.d.ts +84 -0
- package/types/components/exchange/message-observer.d.ts +87 -0
- package/types/components/exchange/message-receiver.d.ts +91 -0
- package/types/components/exchange/message-sender.d.ts +68 -0
- package/types/components/exchange/message-tracer.d.ts +84 -0
- package/types/components/service-caller.d.ts +68 -0
- package/types/components/service-consumer.d.ts +81 -0
- package/types/components/service-executor.d.ts +101 -0
- package/types/components/service-instance.d.ts +111 -0
- package/types/components/service-provider.d.ts +120 -0
- package/types/integrations/redis-integration.d.ts +223 -0
- package/types/utils/cache.d.ts +320 -0
- package/types/utils/config.d.ts +40 -0
- package/types/utils/exceptions.d.ts +224 -0
- package/types/utils/localization.d.ts +194 -0
- package/types/utils/logger.d.ts +24 -0
- package/types/utils/tools.d.ts +70 -0
- package/utils/cache.js +0 -1
- package/utils/exceptions.js +2 -0
- package/utils/localization.js +2 -0
- package/utils/logger.js +2 -0
- package/utils/tools.js +10 -8
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export = MessageSender;
|
|
2
|
+
import MessageHandler = require("#message-handler");
|
|
3
|
+
import type { Message } from "#definitions";
|
|
4
|
+
/** @import { Message } from "#definitions" */
|
|
5
|
+
/**
|
|
6
|
+
* An abstract class that defines a basic message sender behavior.
|
|
7
|
+
*
|
|
8
|
+
* @class MessageSender
|
|
9
|
+
* @extends MessageHandler
|
|
10
|
+
* @abstract
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
declare class MessageSender extends MessageHandler {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* @constructor
|
|
17
|
+
* @param {string} identifier An identifier for this message handler. Should be unique in the context of the message exchange.
|
|
18
|
+
* @throws {TiException.E_GEN_ABSTRACT_CLASS_INIT} If this class is instantiated directly.
|
|
19
|
+
*/
|
|
20
|
+
constructor(identifier: string);
|
|
21
|
+
/**
|
|
22
|
+
* Used to initialize and enable the communication capabilities of the handler.
|
|
23
|
+
* <br/>
|
|
24
|
+
* NOTE: Override this to add functionality.
|
|
25
|
+
*
|
|
26
|
+
* @method
|
|
27
|
+
* @returns {Promise}
|
|
28
|
+
* @abstract
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
enable(): Promise<any>;
|
|
32
|
+
/**
|
|
33
|
+
* Used to shut down and disable the communication behavior of the handler.
|
|
34
|
+
* <br/>
|
|
35
|
+
* NOTE: Override this to add functionality.
|
|
36
|
+
*
|
|
37
|
+
* @method
|
|
38
|
+
* @returns {Promise}
|
|
39
|
+
* @abstract
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
disable(): Promise<any>;
|
|
43
|
+
/**
|
|
44
|
+
* Used to send a {@link Message} via this message handler.
|
|
45
|
+
*
|
|
46
|
+
* @method
|
|
47
|
+
* @param {Message} message The message to send.
|
|
48
|
+
* @param {string} queue The route to destination (queue) for the message as recognized by the {@link MessageExchange} implementation.
|
|
49
|
+
* @returns {Promise}
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
send(message: Message, queue: string): Promise<any>;
|
|
53
|
+
/**
|
|
54
|
+
* Used to perform the actual sending of a message.
|
|
55
|
+
* <br/>
|
|
56
|
+
* NOTE: This method will be called automatically even if overridden.
|
|
57
|
+
* <br/>
|
|
58
|
+
* NOTE: Override this to add functionality.
|
|
59
|
+
*
|
|
60
|
+
* @method
|
|
61
|
+
* @param {Message} message The message to send.
|
|
62
|
+
* @param {string} queue The route to destination (queue) for the message as recognized by the {@link MessageExchange} implementation.
|
|
63
|
+
* @returns {Promise<*>}
|
|
64
|
+
* @abstract
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
onSend(message: Message, queue: string): Promise<any>;
|
|
68
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export { messageTypeEnum as messageType };
|
|
2
|
+
export { dispatchEventEnum as dispatchEvent };
|
|
3
|
+
export { messageStateEnum as messageState };
|
|
4
|
+
declare const _exported: Readonly<MessageTracer>;
|
|
5
|
+
export { _exported as instance };
|
|
6
|
+
import type { Message } from "#definitions";
|
|
7
|
+
export type TiMessageType = number;
|
|
8
|
+
/**
|
|
9
|
+
* Enum for listing message types.
|
|
10
|
+
*
|
|
11
|
+
* @readonly
|
|
12
|
+
* @enum {number}
|
|
13
|
+
* @typedef {number} TiMessageType
|
|
14
|
+
*/
|
|
15
|
+
declare let messageTypeEnum: import("#definitions").TiEnumOf<{
|
|
16
|
+
MESSAGE_REQUEST: (string | number)[];
|
|
17
|
+
MESSAGE_RESPONSE: (string | number)[];
|
|
18
|
+
}>;
|
|
19
|
+
export type TiDispatchEvent = number;
|
|
20
|
+
/**
|
|
21
|
+
* Enum for listing dispatch events.
|
|
22
|
+
*
|
|
23
|
+
* @readonly
|
|
24
|
+
* @enum {number}
|
|
25
|
+
* @typedef {number} TiDispatchEvent
|
|
26
|
+
*/
|
|
27
|
+
declare let dispatchEventEnum: import("#definitions").TiEnumOf<{
|
|
28
|
+
DELIVERED: (string | number)[];
|
|
29
|
+
FAILED: (string | number)[];
|
|
30
|
+
RECEIVED: (string | number)[];
|
|
31
|
+
SENT: (string | number)[];
|
|
32
|
+
}>;
|
|
33
|
+
export type TiMessageState = number;
|
|
34
|
+
/**
|
|
35
|
+
* Enum for listing message states.
|
|
36
|
+
*
|
|
37
|
+
* @readonly
|
|
38
|
+
* @enum {number}
|
|
39
|
+
* @typedef {number} TiMessageState
|
|
40
|
+
*/
|
|
41
|
+
declare let messageStateEnum: import("#definitions").TiEnumOf<{
|
|
42
|
+
PENDING: (string | number)[];
|
|
43
|
+
PROCESSED: (string | number)[];
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Used for recording message trace entries.
|
|
47
|
+
*
|
|
48
|
+
* @class MessageTracer
|
|
49
|
+
* @singleton
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
declare class MessageTracer {
|
|
53
|
+
#private;
|
|
54
|
+
/**
|
|
55
|
+
* @constructor
|
|
56
|
+
* @return {MessageTracer}
|
|
57
|
+
*/
|
|
58
|
+
constructor();
|
|
59
|
+
/**
|
|
60
|
+
* Used to initialize the message tracer.
|
|
61
|
+
*
|
|
62
|
+
* @method
|
|
63
|
+
* @returns {Promise}
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
initialize(): Promise<any>;
|
|
67
|
+
/**
|
|
68
|
+
* Used to create a trace entry for the provided {@link Message} and parameters.
|
|
69
|
+
* <br/>
|
|
70
|
+
* NOTE: By default, all trace events are stored in the memory cache for further processing and analysis. The
|
|
71
|
+
* location is configured in the MESSAGE_EXCHANGE_TRACE_REPOSITORY setting.
|
|
72
|
+
* <br/>
|
|
73
|
+
* NOTE: Trace events are logged with severity level NOTICE or ERROR for failed dispatches. They still might be
|
|
74
|
+
* filtered out if the minimum log level setting is set too high.
|
|
75
|
+
*
|
|
76
|
+
* @method
|
|
77
|
+
* @param {Message} message The message to trace.
|
|
78
|
+
* @param {TiMessageType} messageType The type of the message.
|
|
79
|
+
* @param {TiDispatchEvent} dispatchEvent The event in the dispatch system that triggered the trace entry.
|
|
80
|
+
* @param {TiMessageState} messageState The state of the message processing.
|
|
81
|
+
* @public
|
|
82
|
+
*/
|
|
83
|
+
recordTraceEntry(message: Message, messageType: TiMessageType, dispatchEvent: TiDispatchEvent, messageState: TiMessageState): void;
|
|
84
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export = ServiceCaller;
|
|
2
|
+
import MessageObserver = require("#message-observer");
|
|
3
|
+
import type { ServiceAddress, ServiceCall, ServiceCallResult, ServiceExecContext } from "#definitions";
|
|
4
|
+
/**
|
|
5
|
+
* A class defining a service caller behavior.
|
|
6
|
+
*
|
|
7
|
+
* @class ServiceCaller
|
|
8
|
+
* @extends MessageObserver
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
declare class ServiceCaller extends MessageObserver {
|
|
12
|
+
#private;
|
|
13
|
+
/**
|
|
14
|
+
* @constructor
|
|
15
|
+
*/
|
|
16
|
+
constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Used to call a service in the service ecosystem asynchronously.
|
|
19
|
+
* <br/>
|
|
20
|
+
* NOTE: This method will time out after specific preconfigured time, in which case it will resolve with {@link E_COM_SERVICE_EXEC_TIMEOUT} error.
|
|
21
|
+
*
|
|
22
|
+
* @method
|
|
23
|
+
* @param {ServiceAddress} serviceAddress The service address has to define a valid service domain name, service alias, and optionally a service version.
|
|
24
|
+
* @param {Object} serviceParams Set of named parameters to provide to the called service.
|
|
25
|
+
* @param {ServiceExecContext} serviceExecContext The context in which the service call is being executed.
|
|
26
|
+
* @returns {Promise<ServiceCallResult>} Will always return a service call result that can be either successful or not.
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
executeServiceCall(serviceAddress: ServiceAddress, serviceParams: Object, serviceExecContext: ServiceExecContext): Promise<ServiceCallResult>;
|
|
30
|
+
/**
|
|
31
|
+
* Once the proper message is received this method will trigger the completion of the pending {@link ServiceCall} execution started in {@link #executeServiceCall}.
|
|
32
|
+
*
|
|
33
|
+
* @method
|
|
34
|
+
* @param {string} identifier The identifier of the observed connection.
|
|
35
|
+
* @param {ServiceCall} serviceCall The service call message for processing.
|
|
36
|
+
* @returns {ServiceCall} The service call message that was received.
|
|
37
|
+
* @override
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
onMessage(identifier: string, serviceCall: ServiceCall): ServiceCall;
|
|
41
|
+
/**
|
|
42
|
+
* Needs to be invoked by the connection handler when the connection is disrupted.
|
|
43
|
+
*
|
|
44
|
+
* @method
|
|
45
|
+
* @param {string} identifier The identifier of the observed connection.
|
|
46
|
+
* @override
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
49
|
+
onConnectionDisrupted(identifier: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* Needs to be invoked by the connection handler when the connection is recovered.
|
|
52
|
+
*
|
|
53
|
+
* @method
|
|
54
|
+
* @param {string} identifier The identifier of the observed connection.
|
|
55
|
+
* @override
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
58
|
+
onConnectionRecovered(identifier: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Needs to be invoked by the connection handler when the connection is irrevocably lost.
|
|
61
|
+
*
|
|
62
|
+
* @method
|
|
63
|
+
* @param {string} identifier The identifier of the observed connection.
|
|
64
|
+
* @override
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
onConnectionLost(identifier: string): void;
|
|
68
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export = ServiceConsumer;
|
|
2
|
+
import ServiceInstance = require("#service-instance");
|
|
3
|
+
import type { ServiceAddress, ServiceCallResult, ServiceConfiguration, ServiceExecContext } from "#definitions";
|
|
4
|
+
/** @import { ServiceAddress, ServiceCallResult, ServiceConfiguration, ServiceExecContext } from "#definitions" */
|
|
5
|
+
/**
|
|
6
|
+
* Abstract class used to define a Service Consumer behavior.
|
|
7
|
+
* <br/>
|
|
8
|
+
* NOTE: Inherit this to create a module that can be started as a microservice consumer instance.
|
|
9
|
+
* <br/>
|
|
10
|
+
* NOTE: A service consumer is a microservice that can invoke named business services in the APIs of other
|
|
11
|
+
* microservices using {@link ServiceCall} objects. The consumer does not need to know the specifics of
|
|
12
|
+
* the business logic in these services but only the service address and the inbound parameters (if any).
|
|
13
|
+
* The result of the execution will be returned to the consumer in a {@link ServiceCallResult} object.
|
|
14
|
+
*
|
|
15
|
+
* @class ServiceConsumer
|
|
16
|
+
* @extends ServiceInstance
|
|
17
|
+
* @abstract
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
declare class ServiceConsumer extends ServiceInstance {
|
|
21
|
+
#private;
|
|
22
|
+
/**
|
|
23
|
+
* @constructor
|
|
24
|
+
* @param {string} serviceDomainName The service domain name for this service instance.
|
|
25
|
+
* @param {ServiceConfiguration} [serviceConfig] The JSON configuration for this service.
|
|
26
|
+
* @throws {TiException.E_GEN_ABSTRACT_CLASS_INIT} If this class is instantiated directly.
|
|
27
|
+
*/
|
|
28
|
+
constructor(serviceDomainName: string, serviceConfig?: ServiceConfiguration);
|
|
29
|
+
/**
|
|
30
|
+
* Perform initialization tasks when the service consumer starts.
|
|
31
|
+
* <br/>
|
|
32
|
+
* NOTE: This method will be invoked automatically.
|
|
33
|
+
* <br/>
|
|
34
|
+
* NOTE: If you need to add more onStart logic you can override this method but make sure to call it in the
|
|
35
|
+
* overriding method using: super.onStart()
|
|
36
|
+
*
|
|
37
|
+
* @method
|
|
38
|
+
* @returns {Promise}
|
|
39
|
+
* @override
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
onStart(): Promise<any>;
|
|
43
|
+
/**
|
|
44
|
+
* Perform shut down and cleanup tasks when the service consumer stops.
|
|
45
|
+
* <br/>
|
|
46
|
+
* NOTE: This method will be invoked automatically.
|
|
47
|
+
* <br/>
|
|
48
|
+
* NOTE: If you need to add more onStop logic you can override this method but make sure to call it in the
|
|
49
|
+
* overriding method using: super.onStop()
|
|
50
|
+
*
|
|
51
|
+
* @method
|
|
52
|
+
* @returns {Promise}
|
|
53
|
+
* @override
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
onStop(): Promise<any>;
|
|
57
|
+
/**
|
|
58
|
+
* Used to report health status of the service instance for external monitoring.
|
|
59
|
+
* This is a scheduled job that will be executed at SERVICE_HEALTH_CHECK_INTERVAL time.
|
|
60
|
+
* <br/>
|
|
61
|
+
* NOTE: By default this method will update a Redis key with an expiration timer. You can override this
|
|
62
|
+
* functionality with something custom like calling an HTTP endpoint.
|
|
63
|
+
*
|
|
64
|
+
* @method
|
|
65
|
+
* @override
|
|
66
|
+
* @virtual
|
|
67
|
+
* @public
|
|
68
|
+
*/
|
|
69
|
+
reportHealthy(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Used to invoke a business service in any {@link ServiceInstance}.
|
|
72
|
+
*
|
|
73
|
+
* @method
|
|
74
|
+
* @param {ServiceAddress} serviceAddress
|
|
75
|
+
* @param {Object} serviceParams
|
|
76
|
+
* @param {ServiceExecContext} serviceExecContext
|
|
77
|
+
* @returns {Promise<ServiceCallResult>}
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
callService(serviceAddress: ServiceAddress, serviceParams: Object, serviceExecContext: ServiceExecContext): Promise<ServiceCallResult>;
|
|
81
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export = ServiceExecutor;
|
|
2
|
+
import MessageObserver = require("#message-observer");
|
|
3
|
+
import ServiceInstance = require("#service-instance");
|
|
4
|
+
import type { ServiceAddress, ServiceCall, ServiceDefinition, ServiceExecContext, ServiceInterface } from "#definitions";
|
|
5
|
+
export type VerifyAccessMethod = (authToken: string, serviceAddress: ServiceAddress) => Promise<any>;
|
|
6
|
+
export type ServiceHandlerMethod = (serviceDefinition: ServiceDefinition, serviceParams: Object, serviceExecContext: ServiceExecContext) => Promise<Object | undefined>;
|
|
7
|
+
/** @import { ServiceAddress, ServiceCall, ServiceDefinition, ServiceExecContext, ServiceInterface } from "#definitions" */
|
|
8
|
+
/**
|
|
9
|
+
* @callback VerifyAccessMethod
|
|
10
|
+
* @param {string} authToken
|
|
11
|
+
* @param {ServiceAddress} serviceAddress
|
|
12
|
+
* @returns {Promise<*>}
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* @callback ServiceHandlerMethod
|
|
16
|
+
* @param {ServiceDefinition} serviceDefinition The service definition as provided during the service registration.
|
|
17
|
+
* @param {Object} serviceParams Set of named parameters provided to the called service.
|
|
18
|
+
* @param {ServiceExecContext} serviceExecContext The context in which the service call is being executed.
|
|
19
|
+
* @returns {Promise<Object|undefined>} Optional payload to be returned to the service caller.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* A class defining a service executor behavior.
|
|
23
|
+
*
|
|
24
|
+
* @class ServiceExecutor
|
|
25
|
+
* @extends MessageObserver
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
declare class ServiceExecutor extends MessageObserver {
|
|
29
|
+
#private;
|
|
30
|
+
/**
|
|
31
|
+
* @constructor
|
|
32
|
+
*/
|
|
33
|
+
constructor();
|
|
34
|
+
/**
|
|
35
|
+
* Property returning the current service interface.
|
|
36
|
+
*
|
|
37
|
+
* @property
|
|
38
|
+
* @returns {ServiceInterface}
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
get serviceInterface(): ServiceInterface;
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
*
|
|
45
|
+
* @method
|
|
46
|
+
* @param {string} identifier The identifier of the observed connection.
|
|
47
|
+
* @param {ServiceCall} serviceCall The service call message for processing.
|
|
48
|
+
* @returns {ServiceCall} The service call message that was received.
|
|
49
|
+
* @override
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
onMessage(identifier: string, serviceCall: ServiceCall): ServiceCall;
|
|
53
|
+
/**
|
|
54
|
+
* Needs to be invoked by the connection handler when the connection is disrupted.
|
|
55
|
+
*
|
|
56
|
+
* @method
|
|
57
|
+
* @param {string} identifier The identifier of the observed connection.
|
|
58
|
+
* @override
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
onConnectionDisrupted(identifier: string): void;
|
|
62
|
+
/**
|
|
63
|
+
* Needs to be invoked by the connection handler when the connection is recovered.
|
|
64
|
+
*
|
|
65
|
+
* @method
|
|
66
|
+
* @param {string} identifier The identifier of the observed connection.
|
|
67
|
+
* @override
|
|
68
|
+
* @public
|
|
69
|
+
*/
|
|
70
|
+
onConnectionRecovered(identifier: string): void;
|
|
71
|
+
/**
|
|
72
|
+
* Needs to be invoked by the connection handler when the connection is irrevocably lost.
|
|
73
|
+
*
|
|
74
|
+
* @method
|
|
75
|
+
* @param {string} identifier The identifier of the observed connection.
|
|
76
|
+
* @override
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
onConnectionLost(identifier: string): void;
|
|
80
|
+
/**
|
|
81
|
+
* Used to set up the method for service access verification.
|
|
82
|
+
*
|
|
83
|
+
* @method
|
|
84
|
+
* @param {VerifyAccessMethod} verifyAccess
|
|
85
|
+
* @public
|
|
86
|
+
*/
|
|
87
|
+
configureVerifyAccess(verifyAccess: VerifyAccessMethod): void;
|
|
88
|
+
/**
|
|
89
|
+
* Used to add a service handler to the service interface.
|
|
90
|
+
* <br/>
|
|
91
|
+
* NOTE: If the same version of the service handler already exists, it will be overridden!
|
|
92
|
+
*
|
|
93
|
+
* @method
|
|
94
|
+
* @param {ServiceHandlerMethod} serviceHandler
|
|
95
|
+
* @param {ServiceDefinition} serviceDefinition
|
|
96
|
+
* @param {ServiceInstance} serviceInstance This will be used as context to bind all business services.
|
|
97
|
+
* @returns {Promise}
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
addServiceHandler(serviceHandler: ServiceHandlerMethod, serviceDefinition: ServiceDefinition, serviceInstance: ServiceInstance): Promise<any>;
|
|
101
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
export = ServiceInstance;
|
|
2
|
+
import type { ServiceConfiguration } from "#definitions";
|
|
3
|
+
/** @import { ServiceConfiguration } from "#definitions" */
|
|
4
|
+
/**
|
|
5
|
+
* Abstract class used to define a Service Instance behavior.
|
|
6
|
+
* <br/>
|
|
7
|
+
* NOTE: Inherit this to create a module that can be started as a microservice instance.
|
|
8
|
+
*
|
|
9
|
+
* @class ServiceInstance
|
|
10
|
+
* @abstract
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
declare class ServiceInstance {
|
|
14
|
+
#private;
|
|
15
|
+
/**
|
|
16
|
+
* @constructor
|
|
17
|
+
* @param {string} serviceDomainName The service domain name for this service instance.
|
|
18
|
+
* @param {ServiceConfiguration} [serviceConfig={ services: [] }] The JSON configuration for this service.
|
|
19
|
+
* @throws {TiException.E_GEN_ABSTRACT_CLASS_INIT} If this class is instantiated directly.
|
|
20
|
+
* @throws {TiException.E_GEN_FEATURE_UNSUPPORTED} If multiple instances are started in the same process.
|
|
21
|
+
*/
|
|
22
|
+
constructor(serviceDomainName: string, serviceConfig?: ServiceConfiguration);
|
|
23
|
+
/**
|
|
24
|
+
* Property returning the current service instance ID.
|
|
25
|
+
*
|
|
26
|
+
* @property
|
|
27
|
+
* @returns {string}
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
static get instanceID(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Property returning the current service domain name.
|
|
33
|
+
*
|
|
34
|
+
* @property
|
|
35
|
+
* @returns {string}
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
static get serviceDomainName(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Property to indicate that this and every child class is a {@link ServiceInstance}.
|
|
41
|
+
*
|
|
42
|
+
* @property
|
|
43
|
+
* @returns {boolean}
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
get isServiceInstance(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Property returning the service configuration JSON.
|
|
49
|
+
*
|
|
50
|
+
* @property
|
|
51
|
+
* @returns {ServiceConfiguration}
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
get serviceConfig(): ServiceConfiguration;
|
|
55
|
+
/**
|
|
56
|
+
* Initializes the instance.
|
|
57
|
+
*
|
|
58
|
+
* @method
|
|
59
|
+
* @returns {Promise}
|
|
60
|
+
* @public
|
|
61
|
+
*/
|
|
62
|
+
start(): Promise<any>;
|
|
63
|
+
/**
|
|
64
|
+
* Executes custom logic on instance start.
|
|
65
|
+
* <br/>
|
|
66
|
+
* NOTE: This method will be invoked automatically.
|
|
67
|
+
* <br/>
|
|
68
|
+
* NOTE: If you need to add more onStart logic, you can override this method but make sure to call it in the
|
|
69
|
+
* overriding method using: super.onStart()
|
|
70
|
+
*
|
|
71
|
+
* @method
|
|
72
|
+
* @returns {Promise}
|
|
73
|
+
* @virtual
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
onStart(): Promise<any>;
|
|
77
|
+
/**
|
|
78
|
+
* Shuts down the instance.
|
|
79
|
+
*
|
|
80
|
+
* @method
|
|
81
|
+
* @returns {Promise}
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
stop(): Promise<any>;
|
|
85
|
+
/**
|
|
86
|
+
* Executes custom logic on instance stop.
|
|
87
|
+
* <br/>
|
|
88
|
+
* NOTE: This method will be invoked automatically.
|
|
89
|
+
* <br/>
|
|
90
|
+
* NOTE: If you need to add more onStop logic, you can override this method but make sure to call it in the
|
|
91
|
+
* overriding method using: super.onStop()
|
|
92
|
+
*
|
|
93
|
+
* @method
|
|
94
|
+
* @returns {Promise}
|
|
95
|
+
* @virtual
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
onStop(): Promise<any>;
|
|
99
|
+
/**
|
|
100
|
+
* Used to report health status of the service instance for external monitoring.
|
|
101
|
+
* This is a scheduled job that will be executed at SERVICE_HEALTH_CHECK_INTERVAL time.
|
|
102
|
+
* <br/>
|
|
103
|
+
* NOTE: By default, this method will update a Redis key with an expiration timer. You can override this
|
|
104
|
+
* functionality with something custom like calling an HTTP endpoint.
|
|
105
|
+
*
|
|
106
|
+
* @method
|
|
107
|
+
* @virtual
|
|
108
|
+
* @public
|
|
109
|
+
*/
|
|
110
|
+
reportHealthy(): void;
|
|
111
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
export = ServiceProvider;
|
|
2
|
+
import ServiceConsumer = require("#service-consumer");
|
|
3
|
+
import type { ServiceAddress, ServiceConfiguration, ServiceDefinition } from "#definitions";
|
|
4
|
+
import type { ServiceHandlerMethod } from "#service-executor";
|
|
5
|
+
/** @import { ServiceAddress, ServiceConfiguration, ServiceDefinition } from "#definitions" */
|
|
6
|
+
/** @import { ServiceHandlerMethod } from "#service-executor" */
|
|
7
|
+
/**
|
|
8
|
+
* Abstract class used to define a Service Provider behavior.
|
|
9
|
+
* <br/>
|
|
10
|
+
* NOTE: Inherit this to create a module that can be started as a microservice provider instance.
|
|
11
|
+
* <br/>
|
|
12
|
+
* NOTE: A service provider is a microservice that offers an API of named business services that can be invoked by other
|
|
13
|
+
* microservices using {@link ServiceCall} objects. The provider will take care of the actual execution of that service and
|
|
14
|
+
* therefore acts as a "black box". The only necessary items are the service address and optional inbound parameters to be
|
|
15
|
+
* used in that service's logic. The result of the service's execution will be bundled in an {@link ServiceCallResult}
|
|
16
|
+
* object and returned to the caller.
|
|
17
|
+
*
|
|
18
|
+
* @class ServiceProvider
|
|
19
|
+
* @extends ServiceConsumer
|
|
20
|
+
* @abstract
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
declare class ServiceProvider extends ServiceConsumer {
|
|
24
|
+
#private;
|
|
25
|
+
/**
|
|
26
|
+
* @constructor
|
|
27
|
+
* @param {string} serviceDomainName The service domain name for this service instance.
|
|
28
|
+
* @param {ServiceConfiguration} [serviceConfig] The JSON configuration for this service.
|
|
29
|
+
* @throws {TiException.E_GEN_ABSTRACT_CLASS_INIT} If this class is instantiated directly.
|
|
30
|
+
*/
|
|
31
|
+
constructor(serviceDomainName: string, serviceConfig?: ServiceConfiguration);
|
|
32
|
+
/**
|
|
33
|
+
* Perform initialization tasks when the service provider starts.
|
|
34
|
+
* <br/>
|
|
35
|
+
* NOTE: This method will be invoked automatically.
|
|
36
|
+
* <br/>
|
|
37
|
+
* NOTE: If you need to add more onStart logic, you can override this method but make sure to call it in the
|
|
38
|
+
* overriding method using: super.onStart()
|
|
39
|
+
*
|
|
40
|
+
* @method
|
|
41
|
+
* @returns {Promise}
|
|
42
|
+
* @override
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
onStart(): Promise<any>;
|
|
46
|
+
/**
|
|
47
|
+
* Perform shut down and cleanup tasks when the service provider stops.
|
|
48
|
+
* <br/>
|
|
49
|
+
* NOTE: This method will be invoked automatically.
|
|
50
|
+
* <br/>
|
|
51
|
+
* NOTE: If you need to add more onStop logic, you can override this method but make sure to call it in the
|
|
52
|
+
* overriding method using: super.onStop()
|
|
53
|
+
*
|
|
54
|
+
* @method
|
|
55
|
+
* @returns {Promise}
|
|
56
|
+
* @override
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
onStop(): Promise<any>;
|
|
60
|
+
/**
|
|
61
|
+
* Used to report health status of the service instance for external monitoring.
|
|
62
|
+
* This is a scheduled job that will be executed at SERVICE_HEALTH_CHECK_INTERVAL time.
|
|
63
|
+
* <br/>
|
|
64
|
+
* NOTE: By default, this method will update a Redis key with an expiration timer. You can override this
|
|
65
|
+
* functionality with something custom like calling an HTTP endpoint.
|
|
66
|
+
*
|
|
67
|
+
* @method
|
|
68
|
+
* @override
|
|
69
|
+
* @virtual
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
72
|
+
reportHealthy(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Used to verify whether the service caller has authorization to access the service.
|
|
75
|
+
* <br/>
|
|
76
|
+
* NOTE: Override this to implement authorization check. By default, this method simply returns.
|
|
77
|
+
*
|
|
78
|
+
* @method
|
|
79
|
+
* @param {string} authToken
|
|
80
|
+
* @param {ServiceAddress} serviceAddress
|
|
81
|
+
* @return {Promise}
|
|
82
|
+
* @virtual
|
|
83
|
+
* @public
|
|
84
|
+
*/
|
|
85
|
+
verifyAccess(authToken: string, serviceAddress: ServiceAddress): Promise<any>;
|
|
86
|
+
/**
|
|
87
|
+
* Used to register a single service to the service provider's API. One service can have multiple versions accessible at the same time.
|
|
88
|
+
* <br/>
|
|
89
|
+
* NOTE: This will actually bind the serviceDefinition as the first parameter of the service handler function. When creating default service handlers,
|
|
90
|
+
* keep in mind that your first param must always be the 'serviceDefinition' and the second one will be the general 'serviceParams' object.
|
|
91
|
+
* <br/>
|
|
92
|
+
* NOTE: Additionally, if you intend to call another service inside the service handler, then you have to use a normal function for the handler and not
|
|
93
|
+
* an arrow function! Arrow functions cannot bind the scope of the parent class to themselves, and you won't have access to it and its methods.
|
|
94
|
+
*
|
|
95
|
+
* @method
|
|
96
|
+
* @param {ServiceDefinition} serviceDefinition Full service definition object.
|
|
97
|
+
* @param {ServiceHandlerMethod} [defaultServiceHandler=undefined] A default service handler in case there is one.
|
|
98
|
+
* @return {Promise}
|
|
99
|
+
* @public
|
|
100
|
+
*/
|
|
101
|
+
registerService(serviceDefinition: ServiceDefinition, defaultServiceHandler?: ServiceHandlerMethod): Promise<any>;
|
|
102
|
+
/**
|
|
103
|
+
* Used to register multiple services from the provided service definitions.
|
|
104
|
+
*
|
|
105
|
+
* @method
|
|
106
|
+
* @param {ServiceDefinition[]} serviceDefinitions
|
|
107
|
+
* @param {ServiceHandlerMethod} [defaultServiceHandler=undefined]
|
|
108
|
+
* @return {Promise}
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
registerServices(serviceDefinitions: ServiceDefinition[], defaultServiceHandler?: ServiceHandlerMethod): Promise<any>;
|
|
112
|
+
/**
|
|
113
|
+
* Used to get an ordered list of all currently registered services. This does not include the service versions.
|
|
114
|
+
*
|
|
115
|
+
* @method
|
|
116
|
+
* @returns {string[]}
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
getRegisteredServices(): string[];
|
|
120
|
+
}
|