-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
72 changed files
with
10,359 additions
and
3,771 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Example Microservices Application (Non-Containerized) | ||
|
||
## Purpose | ||
|
||
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. | ||
|
||
## Design | ||
|
||
The microservices application consists of six microservices, which are located within the following directories: | ||
|
||
- client | ||
- auth | ||
- items | ||
- inventory | ||
- orders | ||
- event-bus | ||
|
||
The client serves a build version of the React application found in client-dev. | ||
|
||
The application functionality includes: | ||
|
||
- login/logout with a predefined test user | ||
- creating items | ||
- adjustment of item inventories | ||
- creating orders | ||
- throwing an intentional 404 error - sending a request to a non-existent route | ||
|
||
The Chronos NPM package is configured to track these request / response cycles. | ||
|
||
Chronos is instantiated and its tracking functionality enabled by the following code block, found in each service's app.ts file. | ||
|
||
<img src="../../assets/example-microservices-tracker.png" alt="Chronos" title="Chronos" align="center" />\ | ||
|
||
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. | ||
|
||
The common folder maintains code snippets used across each microservice, and is distributed by way of a common NPM package. | ||
|
||
## To Set Up Database for Storing/Retrieving Metrics | ||
## Database and .env setup | ||
|
||
A `sample.env` file, located in the `examples/microservices` folder, has been provided with the necessary enivronmental variables to spin-up the application. | ||
|
||
Create your own `.env` file in the `examples/microservices` folder with the following key/value pairs: | ||
|
||
- `CHRONOS_DB`: `MongoDB` or `PostgreSQL` | ||
- `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 | ||
- `MONGO_URI_AUTH`: A **MongoDB** URI for the `auth` microservice to use | ||
- `MONGO_URI_ITEMS`: A **MongoDB** URI for the `items` microservice to use | ||
- `MONGO_URI_INVENTORY`: A **MongoDB** URI for the `inventory` microservice to use | ||
- `MONGO_URI_ORDERS`: A **MongoDB** URI for the `orders` microservice to use | ||
- `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 | ||
- `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 | ||
|
||
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. | ||
|
||
## Start the Microservices | ||
|
||
To spin up the example application: | ||
|
||
1. `cd` into the `examples/microservices` folder | ||
2. Run `npm run pkg:install` to install all necessary dependencies | ||
3. Run `npm start` | ||
|
||
Open a web browser to `localhost:5000` to send requests from the client | ||
|
||
Your microservice health metrics may be viewed in the given `CHRONOS_URI` database, or in the Electron.js desktop application. | ||
|
||
## Additional Documentation | ||
|
||
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). | ||
|
||
## Contributing | ||
|
||
Chronos hopes to inspire an active community of both users and developers. For questions, comments, or contributions, please submit a pull request. | ||
|
||
Read our [contributing README](../../CONTRIBUTING.md) to further learn how you can take part in improving Chronos. | ||
|
||
## License | ||
|
||
[MIT](https://github.com/oslabs-beta/Chronos/blob/master/LICENSE.md) |
Oops, something went wrong.