You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples_new/microservices/README.md
+22-27Lines changed: 22 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
## Purpose
4
4
5
-
An example microservices application for testing the [Chronos App](https://github.com/open-source-labs/Chronos). The [Chronos NPM package](https://www.npmjs.com/package/@chronosmicro/tracker) is installed and configured in each service to track metrics on communcation between services such as request and response cycles. Below are instructions for demo-ing Chronos with this example application.
5
+
An example microservices application for testing the [Chronos App](https://github.com/open-source-labs/Chronos). The [Chronos NPM package](https://www.npmjs.com/package/@chronosmicro/tracker) is installed and configured in each service to track metrics on communcation between services such as request and response cycles. Below are instructions for demo-ing Chronos functionality.
6
6
7
7
## Design
8
8
@@ -23,56 +23,51 @@ The application functionality includes:
23
23
- creating items
24
24
- adjustment of item inventories
25
25
- creating orders
26
-
- throwing a 404 error - sending request to non-existent route
26
+
- throwing an intentional 404 error - sending a request to a non-existent route
27
27
28
28
The Chronos NPM package is configured to track these request / response cycles.
29
29
30
-
The Event Bus serves as the intermediary between the backend services, facilitating communication by emitting and receiving numerous types of events and relaying them from one service to another. [review]
30
+
Chronos is instantiated and its tracking functionality enabled by the following code block, found in each service's app.ts file.
31
31
32
-
The Event Bus facilitates communication between the backend services. [review]
Additionally, there is a common folder and a client-dev folder. In common, there can be found both a src and build folder. src contains (in Typescript) files common to each of the microservices. The related folder, build, will contain, after having run the scripts detailed in the package.json file, the resultant compiled Javascript files to be used by the corresponding services.
34
+
The Event Bus serves as the intermediary between the backend services, facilitating communication between them. It receives and emits events whenever a resource is created.
35
35
36
-
Each microservice has its own server, which receives requests from both the client and from other microservices. Books, Customers, and Orders also have their own databases, which they can query to respond to those requests.
37
-
38
-
## Additional Documentation
39
-
40
-
For additional information on how Chronos works this example, please review the microservices section in the [Chronos NPM Package README](../../chronos_npm_package/README.md).
36
+
The common folder maintains code snippets used across each microservice, and is distributed by way of a common NPM package.
41
37
42
38
## To Set Up Database for Storing/Retrieving Metrics
39
+
## Database and .env setup
43
40
44
-
Create a single .env file in the _examples/microservices_ folder with the following key/value pairs:
41
+
A `sample.env` file, located in the `examples/microservices` folder, has been provided with the necessary enivronmental variables to spin-up the application.
42
+
43
+
Create your own `.env` file in the `examples/microservices` folder with the following key/value pairs:
45
44
46
45
-`CHRONOS_DB`: `MongoDB` or `PostgreSQL`
47
-
-`CHRONOS_URI`: The URI to the desired MongoDB or PostgreSQL database to save health metrics via**Chronos NPM Package**
46
+
-`CHRONOS_URI`: The URI to the desired MongoDB or PostgreSQL database where the **Chronos NPM Package** will store recorded metrics. The**Chronos desktop application** retrieves and displays metrics from this database
48
47
-`MONGO_URI_AUTH`: A **MongoDB** URI for the `auth` microservice to use
49
48
-`MONGO_URI_ITEMS`: A **MongoDB** URI for the `items` microservice to use
50
49
-`MONGO_URI_INVENTORY`: A **MongoDB** URI for the `inventory` microservice to use
51
50
-`MONGO_URI_ORDERS`: A **MongoDB** URI for the `orders` microservice to use
52
-
-`MONGO_URI_CLIENT`: A **MongoDB** URI for the `client` microservice to use
53
-
-`JWT_KEY`: A random string used to sign and and verify JSON Web Tokens used by the auth service - the random string provided in **sample.env** will work
54
-
-`JWT_LIFETIME`: The time-to-expiration of the JSON Web Token used by the auth service - this is set to **"1d"** in **sample.env** meaning user authentication is valid for 1 day
51
+
-`JWT_KEY`: A random string used to sign and verify JSON Web Tokens used by the auth service - the random string provided in **sample.env** will work
52
+
-`JWT_LIFETIME`: The time-to-expiration of the JSON Web Token used by the auth service - this is set to `1d` in `sample.env` meaning user authentication is valid for 1 day
55
53
56
-
Note: The `CHRONOS_URI` and all microservice `_URI`'s can be the same URI if you use MongoDB. You may run out of space in your database if the services run for an extended period of time. You can temporarily solve this by creating separate databases, or manually deleting the collection from the database regularly using a UI such as MongoDB Compass. When running, the microservices will create new collections if none are found in the database.
54
+
Note: You may run out of space in your database if the services run for an extended period of time. You can temporarily solve this by manually deleting the collection from the database regularly using a UI such as MongoDB Compass.
57
55
58
56
## Start the Microservices
59
57
60
-
Peform the following steps in each of the _books_, _customers_, _orders_, and _reverse_proxy_ directories
61
-
62
-
1.`cd` into the folder
63
-
2. Look at `package.json` to note where `@chronosmicro/tracker` is being imported from. Verify that it is coming from the desired location (whether the published remote from npm or from local directory).
64
-
3. Run `npm install`
65
-
4. Run `npm run start`
58
+
To spin up the example application:
66
59
67
-
**Mac Users:** Alternative to the above list of steps, `cd` into the `scripts` folder and run the `startMicroservices.sh` script
60
+
1.`cd` into the `examples/microservices` folder
61
+
2. Run `npm run pkg:install` to install all necessary dependencies
62
+
3. Run `npm start`
68
63
69
-
#
64
+
Open a web browser to `localhost:5000` to send requests from the client
70
65
71
-
Then open a web browser to `localhost:3000` and verify that the simple webpage application is operational. You can use the web app if you wish, but it is not necessary for retrieving and visualizing health metrics in Chronos.
66
+
Your microservice health metrics may be viewed in the given `CHRONOS_URI` database, or in the Electron.js desktop application.
72
67
73
-
Your microservice health metrics can now be viewed in the given `CHRONOS_URI` database, or, preferrably, in the Electron.js desktop application.
68
+
## Additional Documentation
74
69
75
-
#
70
+
For additional information on how Chronos works this example, please review the microservices section in the [Chronos NPM Package README](../../chronos_npm_package/README.md).
0 commit comments