Skip to content

Commit cbdafd5

Browse files
authored
Merge pull request #28 from oslabs-beta/ms-ex-cleanup
Microservices Example complete
2 parents 717af05 + 1bc6b4e commit cbdafd5

72 files changed

Lines changed: 10336 additions & 3763 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
24.8 KB
Loading
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Example Microservices Application (Non-Containerized)
2+
3+
## Purpose
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 functionality.
6+
7+
## Design
8+
9+
The microservices application consists of six microservices, which are located within the following directories:
10+
11+
- client
12+
- auth
13+
- items
14+
- inventory
15+
- orders
16+
- event-bus
17+
18+
The client serves a build version of the React application found in client-dev.
19+
20+
The application functionality includes:
21+
22+
- login/logout with a predefined test user
23+
- creating items
24+
- adjustment of item inventories
25+
- creating orders
26+
- throwing an intentional 404 error - sending a request to a non-existent route
27+
28+
The Chronos NPM package is configured to track these request / response cycles.
29+
30+
Chronos is instantiated and its tracking functionality enabled by the following code block, found in each service's app.ts file.
31+
32+
<img src="../../assets/example-microservices-tracker.png" alt="Chronos" title="Chronos" align="center" />\
33+
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+
36+
The common folder maintains code snippets used across each microservice, and is distributed by way of a common NPM package.
37+
38+
## To Set Up Database for Storing/Retrieving Metrics
39+
## Database and .env setup
40+
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:
44+
45+
- `CHRONOS_DB`: `MongoDB` or `PostgreSQL`
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
47+
- `MONGO_URI_AUTH`: A **MongoDB** URI for the `auth` microservice to use
48+
- `MONGO_URI_ITEMS`: A **MongoDB** URI for the `items` microservice to use
49+
- `MONGO_URI_INVENTORY`: A **MongoDB** URI for the `inventory` microservice to use
50+
- `MONGO_URI_ORDERS`: A **MongoDB** URI for the `orders` microservice to use
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
53+
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.
55+
56+
## Start the Microservices
57+
58+
To spin up the example application:
59+
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`
63+
64+
Open a web browser to `localhost:5000` to send requests from the client
65+
66+
Your microservice health metrics may be viewed in the given `CHRONOS_URI` database, or in the Electron.js desktop application.
67+
68+
## Additional Documentation
69+
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).
71+
72+
## Contributing
73+
74+
Chronos hopes to inspire an active community of both users and developers. For questions, comments, or contributions, please submit a pull request.
75+
76+
Read our [contributing README](../../CONTRIBUTING.md) to further learn how you can take part in improving Chronos.
77+
78+
## License
79+
80+
[MIT](https://github.com/oslabs-beta/Chronos/blob/master/LICENSE.md)

0 commit comments

Comments
 (0)