@ti-engine/core 1.0.6 → 1.0.10

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/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
  Flexible framework for the creation of microservices with [node.js](https://nodejs.org/).
3
3
 
4
4
  ## introduction
5
- The **ti-engine** is an open source, free to use - both for personal and commercial projects - framework for the creation of microservice-based solutions using **node.js**. The general architectural concept of the framework is based on a standard messenger system that allows certain customization but also provides predictability and traceability of its behavior.
5
+ The **ti-engine** is an open source, free to use - both for personal and commercial projects - framework for the creation of microservice-based solutions using **node.js**. The architectural concept of the framework is based on a standard _messaging system_ that allows for certain customization but also provides predictability and traceability of its behavior.
6
6
 
7
- Being a messenger system, the **ti-engine** relies on a message broker for the actual exchange of messages between microservice instances. The default implementation of the framework uses [Redis](https://redis.io/) cache, however, you could create your own implementation using something like [Rabbit MQ](https://www.rabbitmq.com/). See the [advanced topics](#advanced-topics) section of this documentation for guides on how to do this.
7
+ Being a messaging system, the **ti-engine** relies on a message broker for the actual exchange of messages between microservice instances. The default implementation of the framework uses [Redis](https://redis.io/) cache, however, you could create your own implementation using something like [Rabbit MQ](https://www.rabbitmq.com/). See the [advanced topics](#advanced-topics) section of this documentation for guides on how to do this.
8
8
 
9
9
  Please be aware, that this framework is under active development and will expand in the near future. Also, this documentation is still in the process of being created and refined. Make sure to keep an eye on the changes in case you want to use it in the meantime.
10
10
 
@@ -23,27 +23,106 @@ These are just some benefits **ti-engine** offers. Get to know it better to find
23
23
 
24
24
  ## prerequisites & installation
25
25
  In order to run the basic ti-engine framework you will need a couple of things:
26
- 1. A local [node.js installation](https://nodejs.org/en/download/) with a minimum version of **14.17.0**
27
- 2. A local or remote [Redis cache installation](https://redis.io/download) with a minimum version of **5.0.14**
26
+ * A local [node.js installation](https://nodejs.org/en/download/) with a minimum version of **14.17.0**
27
+ * A local or remote [Redis cache installation](https://redis.io/download) with a minimum version of **5.0.14**
28
+
29
+ If you are working under Windows OS and you need to install Redis, take a look at this [guide](https://redis.com/blog/redis-on-windows-10/).
28
30
 
29
31
  To get the framework itself, use the command `npm install @ti-engine/core`. And to include it directly in your package.json dependencies execute `npm install @ti-engine/core --save-prod`.
30
32
 
31
33
  ## getting started
32
- To start using the **ti-engine**, you will have to make sure that all prerequisites are available and operational. If you are working under Windows OS and you need to install Redis, take a look at this [guide](https://redis.com/blog/redis-on-windows-10/).
34
+ To start using the **ti-engine**, you will have to make sure that all prerequisites are available and operational. However, before we get to the fun part you need to also consider a couple of very important things while working with this framework:
35
+ 1. The runtime configuration of the framework can be customized using ENV variables. These can be provided to node.js in all the standard ways, but there is also an option to include an `.env` file.
36
+ 2. It loads your framework-related custom scripts and files dynamically, but it always assumes their provided paths are relative to the _current working directory_ (i.e. it uses `process.cwd()`). Be mindful of that whenever you declare file paths in the various settings.
37
+
38
+ Once you have everything else ready, you should download the **ti-engine** tester module with the command `npm install @ti-engine/tester`. The tester module packages an example microservice that shows the basic approach for using the framework. To make sure everything is working properly, you should try and start the tester service:
39
+ 1. Open a command prompt and navigate to the directory of the tester module; it should be something like that:
40
+ `[path to your project]/node_modules/@ti-engine/tester`
41
+ 2. Execute the following command `node ../core/bin/start-instance.js`
42
+ 3. If everything was done properly, you should see the following output:
43
+ ```text
44
+ [timestamp]: [instance-id] - notice - Starting new instance of type 'tester-service' with instance ID '[instance-id]'.
45
+ [timestamp]: [instance-id] - info - Starting service registration process. There is NO default service handler provided.
46
+ [timestamp]: [instance-id] - info - Registration of defined services completed with 2 successful out of 2 total.
47
+ [timestamp]: [instance-id] - notice - Instance '[instance-id]' started successfully.
48
+ [timestamp]: [instance-id] - info - Connection to Redis server 127.0.0.1:6379 (re)established by client 'connection-msg-responses-out' and is ready to be used.
49
+ [timestamp]: [instance-id] - info - Connection to Redis server 127.0.0.1:6379 (re)established by client 'system' and is ready to be used.
50
+ [timestamp]: [instance-id] - info - Connection to Redis server 127.0.0.1:6379 (re)established by client 'connection-msg-requests-in' and is ready to be used.
51
+ [timestamp]: [instance-id] - info - Connection to Redis server 127.0.0.1:6379 (re)established by client 'connection-msg-requests-out' and is ready to be used.
52
+ [timestamp]: [instance-id] - info - Connection to Redis server 127.0.0.1:6379 (re)established by client 'connection-msg-responses-in' and is ready to be used.
53
+ [timestamp]: [instance-id] - notice - Execution of service1 result:
54
+ { exception: undefined, isSuccessful: true, payload: { s1Timestamp: [timestamp] } }
55
+ [timestamp]: [instance-id] - notice - Execution of service2 result:
56
+ { exception: undefined, isSuccessful: true, payload: { s1Timestamp: [timestamp], s2TimestampStart: [timestamp], s2TimestampEnd: [timestamp] } }
57
+ ```
58
+ Now let's analyse that output. For the sake of completeness, the `[timestamp]` and `[instance-id]` are placeholders of the actual values you'll see there. The timestamps are in UTC and show a date followed by time.
59
+
60
+ At the start of the output log you can see a NOTICE that tells you a couple of important things:
61
+ * The instance name - in this case `tester-service`. In the terminology of the framework, this is also known as a _service domain name_.
62
+ * The _instance identificator_. It is an uuid string with a `ti-` prefix, that is generated by the framework at process start. It can and will be used to trace the messages during their movement through the microservice ecosystem. But more on that later.
63
+
64
+ Following that come a couple of INFO lines that inform you about the microservice interface state. The framework starts with the process of registration of _business services_ within the service domain of the microservice `tester-service` and successfully adds 2 such services. The necessary information for this is read from a JSON config file included in the package. We'll get into more details on what this all means in the section [creating a microservice](#creating-a-microservice).
65
+
66
+ Once the initialization sequence has completed the framework informs you that the microservice instance has started successfully. If the framework encountered an error during initialization instead, you would see something like this:
67
+ ```text
68
+ [timestamp]: [instance-id] - notice - Starting new instance of type 'tester-service' with instance ID '[instance-id]'.
69
+ [timestamp]: [instance-id] - alert - Error detected in the instance startup script!
70
+ ```
71
+ The following 5 lines inform you about the successful connection to Redis. The default configuration assumes that your Redis is running on localhost and uses the default port. If you have a different setup, you can provide the host and port via ENV variables. We'll cover that in the section [using the framework](#using-the-framework).
72
+
73
+ Finally, you should see a couple of execution statements with their results in JSON format.
74
+
75
+ You can now kill the node process which should show you the following two lines:
76
+ ```text
77
+ [timestamp]: [instance-id] - notice - SIGINT event detected in main instance process.
78
+ [timestamp]: [instance-id] - notice - Instance '[instance-id]' shut down successfully.
79
+ ```
80
+ The framework will always try to capture the shut-down event and log it. This should work even in container environment, but it might depend on your setup whether the last two entries will reach the logging system or not.
81
+
82
+ The tester module gets its starting configuration from an `.env` file included in the package. If you open it, this is what you'll see:
83
+ ```text
84
+ TI_INSTANCE_CLASS=tester-service.js
85
+ TI_INSTANCE_CONFIG=tester-service.json
86
+ TI_INSTANCE_NAME=tester-service
87
+ TI_LOG_MIN_LEVEL=200
88
+ ```
89
+ The first variable `TI_INSTANCE_CLASS` is mandatory for every microservice you create with the **ti-engine**. It needs to specify the path to the module that is your microservice. Remember, that this path has to be relative to the working directory in which you plan to execute the `node` command. This is especially important when you're configuring your microservices to work in containers. You can find the full list of available ENV variables and what they do below.
90
+
91
+ Before moving on, also take a good look at the file `bin/start-instance.js`. It should give you an idea on how to the process of starting and stopping a microservice operates. In most cases this file should be sufficient as a starting script for your **ti-engine** based microservice applications. You can, of course, create your own starting script, but then you'll have to consider all necessary steps to properly handle the microservice instance.
33
92
 
34
- Once you have all this setup and ready, you should download the **ti-engine** tester module with the command `npm install @ti-engine/tester`. The tester module packages an example microservice that shows the basic approach for using the framework. To make sure everything is working properly, you should try and start the tester service:
35
- 1. Open a command prompt and navigate to the directory of the tester module; it should be something like that `<path to your project>/node_modules/@ti-engine/tester`
36
- 2.
93
+ ## architecture
94
+ The architectural approach for the **ti-engine** is done in _tiers_ with lower tiers being unaware of the tiers above them. The framework prefers a high level of abstraction in all its tiers and provides many options for customization and extension. While the language is JavaScript, the structuring of the framework follows the OOP principles, and you will find a lot of abstract classes and methods that require you to implement them. These are always marked with the `@abstract` annotation but if you happen to miss one, the framework will raise an exception when you try to use it in your solution.
37
95
 
96
+ There are three general tiers in the **ti-engine**:
97
+ 1. message exchange
98
+ 2. service interface
99
+ 3. solution implementation
38
100
 
101
+ See the following sections for more information on each of them.
39
102
 
40
- the framework is properly configured and able to run. More details and instructions will be provided in the next version of this documentation. For now please take a look at the included file `start-instance.js`. It should give you an idea of how the engine operates and what to do in order to create and run your own microservice instance.
103
+ ### tier 1 - message exchange
104
+ This is the lowest framework tier, unless we count the actual data objects processed by the framework. As you already know, the foundational **ti-engine** concept is that of a messaging system. Therefore, the first tier provides an abstraction over a chosen message broker (Redis by default). That abstraction makes it easy to switch between message brokers whenever you want to without having to change anything above tier 1. It also provides several added bonuses that can accelerate your work - message encryption, message tracing, message observers, and others. More details about each of these features will be covered in section [using the framework](#using-the-framework).
41
105
 
106
+ Another important aspect for you to remember is that the message exchange is entirely _asynchronous_. This helps reduce system load and optimizes the usage of the available resources. Even so each node.js process can handle a limited amount of load. Therefore, you should plan for running multiple identical senders and receives in order to scale your solution. But more on that later.
42
107
 
108
+ For now, take a look at the following diagram:
43
109
 
44
- Under development...
110
+ ![Message Exchange](https://github.com/Belleal/ti-engine/blob/master/core/docs/diagram1.png)
45
111
 
46
- ## architecture
112
+ It shows the standard flow of a message exchange between one sender and _n_ identical message receivers. The sender splits each message into an _envelope_ and a _payload_, then stores the payload in the shared cache and enqueues the envelope in the requests (destination) queue. Receivers can subscribe to that queue in order to fetch enqueued messages and process their contents. During the fetch sequence a receiver assembles the full message by getting the payload from the storage. This process is depicted by the blue flow lines.
113
+
114
+ After the processing is done the message payload is modified and the receiver sends the message back to the original sender using the same mechanism. It again splits the message into an envelope and a payload, stores the payload in the storage and enqueues the envelope in the sender response (source) queue. The sender will then assemble the message back and process the contained results. This process is depicted by the red flow lines.
115
+
116
+ In this scenario the framework utilizes _Redis lists_ as queues for the message envelopes and _Redis hash_ as message payload storage. Other message brokers might utilize a slightly different approach, but they should still adhere to the same logical flow.
117
+
118
+ ### tier 2 - service domains
119
+ This tier focuses on hosting and executing the _business logic_ of your application. It's comprised of _business services_ that process input data and return the result of the processing as output data. The business services are grouped in _service domains_, which are in turn hosted inside stateless _microservices_ also named _service instances_. There are two types of service instances in **ti-engine**:
120
+ * Service consumers - these are service instances, that can call business services in any available service domain.
121
+ * Service providers - these are service instances, that host and run a set of business services in a particular service domain. Every service provider is also a service consumer.
122
+
123
+ The various service instances in a solution represent a network of interconnected service domains that contain the business logic of your application. All business services exchange data via _service calls_ using abstract _service addresses_. These service calls are transported from one address in the network to another via the underlying message exchange tier. This, however, is completely transparent to the service instances. In essence, tier 2 does not care about the actual data transportation method or protocol. You could in fact change completely the tier 1 approach without having to modify anything in your business logic and business flow.
124
+
125
+ ### tier 3 - solution implementation
47
126
  Under development...
48
127
 
49
128
  ## creating a microservice
@@ -23,10 +23,9 @@ class DefaultMessageReceiver extends MessageReceiver {
23
23
  * @constructor
24
24
  * @param {string} identifier An identifier for this message handler. Should be unique in the context of the message exchange.
25
25
  * @param {string} receiveQueue The queue from which the messages will be received.
26
- * @param {string} [processingQueue=undefined] The queue in which the messages will be put for processing (if necessary).
27
26
  */
28
- constructor( identifier, receiveQueue, processingQueue = undefined ) {
29
- super( identifier, receiveQueue, processingQueue );
27
+ constructor( identifier, receiveQueue ) {
28
+ super( identifier, receiveQueue );
30
29
  }
31
30
 
32
31
  /**
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ti-engine/core",
3
- "version": "1.0.6",
3
+ "version": "1.0.10",
4
4
  "description": "The ti-engine is an open source, free to use - both for personal and commercial projects - framework for the creation of microservice-based solutions using node.js.",
5
5
  "author": "Boris Kostadinov <kostadinov.boris@gmail.com>",
6
6
  "license": "ISC",
@@ -45,8 +45,8 @@
45
45
  "dotenv": "^10.0.0",
46
46
  "fs-extra": "^10.0.0",
47
47
  "lodash": "^4.17.21",
48
- "node-schedule": "^2.0.0",
49
- "ioredis": "^4.28.1"
48
+ "node-schedule": "^2.1.0",
49
+ "ioredis": "^4.28.2"
50
50
  },
51
51
  "optionalDependencies": {
52
52
  "@google-cloud/error-reporting": "^2.0.4"
package/utils/tools.js CHANGED
@@ -35,7 +35,7 @@ module.exports.getUUID = () => {
35
35
  *
36
36
  * @method
37
37
  * @param {Object} seed
38
- * @returns {TiEnum}
38
+ * @returns {Object}
39
39
  * @public
40
40
  */
41
41
  module.exports.enum = ( seed ) => {