{"id":19872326,"url":"https://github.com/rafaelrok/ms-sales","last_synced_at":"2026-04-14T05:31:56.789Z","repository":{"id":57931208,"uuid":"524142989","full_name":"rafaelrok/ms-sales","owner":"rafaelrok","description":"Microservice Ms-sales, projeto desenvolvendo envolvendo um eco sistema de eCommerce, com gerenciamento de vendas, estoque de produtos e pagamento, a fim de fornecer toda uma estrutura de um shop virtual ","archived":false,"fork":false,"pushed_at":"2023-03-15T03:54:29.000Z","size":1605,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-01T00:58:31.748Z","etag":null,"topics":["docker","docker-compose","flyway","gradle","java","jdk11","kibana","nodejs","postgresql","rabbitmq","spring","spring-security"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rafaelrok.png","metadata":{"files":{"readme":"README-en.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"security-api/.gitignore","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-12T15:46:54.000Z","updated_at":"2024-07-19T01:01:48.000Z","dependencies_parsed_at":"2025-01-11T16:33:24.587Z","dependency_job_id":"6893b7bc-5cb4-4146-8ef0-822dc1edb44c","html_url":"https://github.com/rafaelrok/ms-sales","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rafaelrok/ms-sales","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelrok%2Fms-sales","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelrok%2Fms-sales/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelrok%2Fms-sales/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelrok%2Fms-sales/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rafaelrok","download_url":"https://codeload.github.com/rafaelrok/ms-sales/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelrok%2Fms-sales/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31784251,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-14T02:24:21.117Z","status":"ssl_error","status_checked_at":"2026-04-14T02:24:20.627Z","response_time":153,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-compose","flyway","gradle","java","jdk11","kibana","nodejs","postgresql","rabbitmq","spring","spring-security"],"created_at":"2024-11-12T16:15:08.893Z","updated_at":"2026-04-14T05:31:56.773Z","avatar_url":"https://github.com/rafaelrok.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Project: Microservices - Ms-Sales\n\nThis project was developed in order to explore the communication between services with docker and messaging with RabbitMQ,\nusing RabbitMQ as a message broker, and the behavior of the integration with APIs built with nodejs and express, finally the behavior of the integration with the database.\n\n\u003c!---Esses são exemplos. Veja https://shields.io para outras pessoas ou para personalizar este conjunto de escudos. Você pode querer incluir dependências, status do projeto e informações de licença aqui---\u003e\n\n\u003cp align=\"center\"\u003e\n     \u003cimg alt=\"GitHub language count\" src=\"https://img.shields.io/github/commit-status/rafaelrok/rest-archetypebook_v2/main/0d4a9c360f41bd33e2970edb2c3bdbec3ada6506?logo=git\"\u003e\n     \u003cimg alt=\"Repository size\" src=\"https://img.shields.io/github/repo-size/rafaelrok/rest-archetypebook_v2?logo=github\"\u003e\n     \u003ca href=\"https://twitter.com/RafaelV38440615\"\u003e\n      \u003cimg alt=\"Siga no Twitter\" src=\"https://img.shields.io/twitter/url?url=https://github.com/rafaelrok/rest-archetypebook_v2/edit/main/README.md\"\u003e\n     \u003c/a\u003e  \n     \u003ca href=\"https://github.com/rest-archetypebook_v2/README.md/commits/master\"\u003e\n      \u003cimg alt=\"GitHub last commit\" src=\"https://img.shields.io/github/last-commit/rafaelrok/rest-archetypebook_v2\"\u003e\n     \u003c/a\u003e\n     \u003ca href=\"https://github.com/rafaelrok/rest-archetypebook_v2/blob/main/LICENSE\"\u003e\n      \u003cimg alt=\"License\" src=\"https://img.shields.io/hexpm/l/apa?logo=apache\"\u003e\n     \u003c/a\u003e  \n     \u003ca href=\"https://github.com/tgmarinho/README-ecoleta/stargazers\"\u003e\n      \u003cimg alt=\"Stargazers\" src=\"https://img.shields.io/github/stars/rafaelrok/rest-archetypebook_v2?style=social\"\u003e\n     \u003c/a\u003e\n     \u003ca href=\"https://medium.com/@rafael\"\u003e\n      \u003cimg alt=\"medium\" src=\"https://img.shields.io/twitter/url?label=Medium\u0026logo=medium\u0026style=social\u0026url=https%3A%2F%2Fmedium.com%2F%40rafael.\"\u003e\n     \u003c/a\u003e\n  \u003c/p\u003e\n\n## technologies\n\n* **Java 11**\n* **Spring Boot**\n* **Javascript ES6**\n* **Node.js 14**\n* **ES6 Modules**\n* **Express.js**\n* **MongoDB (Container e Cloud MongoDB)**\n* **API REST**\n* **PostgreSQL (Container e Heroku Postgres)**\n* **RabbitMQ (Container e CloudAMQP)**\n* **Docker**\n* **docker-compose**\n* **JWT**\n* **Spring Cloud OpenFeign**\n* **FlyWay**\n* **Axios**\n* **Heroku**\n* **Coralogix Logging**\n* **Kibana**\n\n## Proposed Architecture\n\nThis project was developed with the following architecture:\n\n![Proposed Architecture](https://github.com/rafaelrok/ms-sales/blob/main/docs/Arquitetura%20ms-sales.png)\n\nComposed of 3 APIs:\n\n* **Auth-API**: Authentication API with Node.js 14, Express.js, Sequelize, PostgreSQL, JWT and Bcrypt.\n* **Sales-API**: Sales API with Node.js 14, Express.js, MongoDB, Mongoose, JWT validation, RabbitMQ and Axios for HTTP clients.\n* **Product-API**: Product API with Java 11, Spring Boot, Spring Data JPA, PostgreSQL, JWT validation, RabbitMQ and Spring Cloud OpenFeign for HTTP clients.\n\nProject also works with apis running via docker containers via docker-compose.\n\n### Execution flow of an order\n\nThe flow for making a request will depend on **synchronous** (HTTP calls via REST) and **asynchronous** (messaging with RabbitMQ) communications.\n\nThe flow is described below:\n\n* 01 - The start of the flow will be by making a request to the order creation endpoint.\n* 02 - The input payload (JSON) will be a list of products informing the ID and the desired quantity.\n* 03 - Before creating the order, a REST call will be made to the products API to validate if there is stock for the purchase of all products.\n* 04 - If any product is out of stock, the products API will return an error, and the sales API will throw an error message stating that there is no stock.\n* 05 - If there is stock, then an order will be created and saved in MongoDB with pending status (PENDING).\n* 06 - When saving the order, a message will be published on RabbitMQ informing the ID of the created order, and the products with their respective IDs and quantities.\n* 07 - The products API will be listening to the queue, so it will receive the message.\n* 08 - Upon receiving the message, the API will revalidate the stock of products, and if all are ok, it will update the stock of each product.\n* 09 - If the stock is updated successfully, the products API will publish a message in the sales confirmation queue with status APPROVED.\n* 10 - If there is a problem with the update, the product API will publish a message in the sales confirmation queue with status REJECTED.\n* 11 - Finally, the order API will receive the confirmation message and update the order with the status returned in the message.\n\n## API Logs and Tracing\n\nAll endpoints need a header called **transactionid**, as it will represent the ID that will go through the entire request in the service, and, if this application calls other microservices, this **transactionid** will be passed on. All input and output endpoints will log the input data (JSON or parameters) and the **transactionid**.\n\nAt each request for each microservice, we will have a **serviceid** attribute generated only for the logs of that service itself. We will then have the **transactionid** that will circulate among all microservices involved in the request, and each microservice will have its own **serviceid**.\n\nTracing flow in requests:\n\n**POST** - **/api/order** with **transactionid**: ef8347eb-2207-4610-86c0-657b4e5851a3\n\n```\nservice-1:\ntransactionid: ef8347eb-2207-4610-86c0-657b4e5851a3\nserviceid    : 6116a0f4-6c9f-491f-b180-ea31bea2d9de\n|\n| HTTP Request\n|----------------\u003e service-2:\n                   transactionid: ef8347eb-2207-4610-86c0-657b4e5851a3\n                   serviceid    : 4e1261c1-9a0c-4a5d-bfc2-49744fd159c6\n                   |\n                   | HTTP Request\n                   |----------------\u003e service-3: /api/check-stock\n                                      transactionid: ef8347eb-2207-4610-86c0-657b4e5851a3\n                                      serviceid    : b4fbc082-a49a-440d-b1d6-2bd0557fd189\n```\n\nAs we can see in the flow above, the **transactionid** ef8347eb-2207-4610-86c0-657b4e5851a3 remained the same in the 3 services, and each service has\nyour own **serviceid**.\n\nExample of a complete flow calling 5 services and generating **transactionid** and **serviceid**:\n\n![Tracing](https://github.com/rafaelrok/ms-sales/blob/main/docs/Tracing.png)\n\nExample of logs in the developed APIs:\n\nAuth-API:\n\n```\nRequest to POST login with data {\"email\":\"testeuser1@gmail.com\",\"password\":\"123456\"} | [transactionID: e3762030-127a-4079-9dee-ba961d7e77ce | serviceID: 6b07b6c2-009e-4799-be96-3bf972338b17]\n\nResponse to POST login with data {\"status\":200,\"accessToken\":\"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdXRoVXNlciI6eyJpZCI6MSwibmFtZSI6IlVzZXIgVGVzdCAxIiwiZW1haWwiOiJ0ZXN0ZXVzZXIxQGdtYWlsLmNvbSJ9LCJpYXQiOjE2MzQwNTE4ODQsImV4cCI6MTYzNDEzODI4NH0.NJ-h2i5XPT8NwZyZ_43bif1NIS00ROfCtRecBkxy5A8\"} | [transactionID: e3762030-127a-4079-9dee-ba961d7e77ce | serviceID: 6b07b6c2-009e-4799-be96-3bf972338b17]\n```\n\nProduct-API:\n\n```\nRequest to POST product stock with data {\"products\":[{\"productId\":1001,\"quantity\":1},{\"productId\":1002,\"quantity\":1},{\"productId\":1003,\"quantity\":1}]} | [transactionID: 8817508e-805c-48fb-9cb4-6a1e5a6e71e9 | serviceID: ea146e74-55cf-4a53-860e-9010d6e3f61b]\n\nResponse to POST product stock with data {\"status\":200,\"message\":\"The stock is ok!\"} | [transactionID: 8817508e-805c-48fb-9cb4-6a1e5a6e71e9 | serviceID: ea146e74-55cf-4a53-860e-9010d6e3f61b]\n```\n\nSales-API:\n\n```\nRequest to POST new order with data {\"products\":[{\"productId\":1001,\"quantity\":1},{\"productId\":1002,\"quantity\":1},{\"productId\":1003,\"quantity\":1}]} | [transactionID: 8817508e-805c-48fb-9cb4-6a1e5a6e71e9 | serviceID: 5f553f02-e830-4bed-bc04-8f71fe16cf28]\n\nResponse to POST login with data {\"status\":200,\"createdOrder\":{\"products\":[{\"productId\":1001,\"quantity\":1},{\"productId\":1002,\"quantity\":1},{\"productId\":1003,\"quantity\":1}],\"user\":{\"id\":1,\"name\":\"User Test 1\",\"email\":\"testeuser1@gmail.com\"},\"status\":\"PENDING\",\"createdAt\":\"2021-10-12T16:34:49.778Z\",\"updatedAt\":\"2021-10-12T16:34:49.778Z\",\"transactionid\":\"8817508e-805c-48fb-9cb4-6a1e5a6e71e9\",\"serviceid\":\"5f553f02-e830-4bed-bc04-8f71fe16cf28\",\"_id\":\"6165b92addaf7fc9dd85dad0\",\"__v\":0}} | [transactionID: 8817508e-805c-48fb-9cb4-6a1e5a6e71e9 | serviceID: 5f553f02-e830-4bed-bc04-8f71fe16cf28]\n```\n\nRabbitMQ:\n\n```\nSending message to product update stock: {\"salesId\":\"6165b92addaf7fc9dd85dad0\",\"products\":[{\"productId\":1001,\"quantity\":1},{\"productId\":1002,\"quantity\":1},{\"productId\":1003,\"quantity\":1}],\"transactionid\":\"8817508e-805c-48fb-9cb4-6a1e5a6e71e9\"}\n\nRecieving message with data: {\"salesId\":\"6165b92addaf7fc9dd85dad0\",\"products\":[{\"productId\":1001,\"quantity\":1},{\"productId\":1002,\"quantity\":1},{\"productId\":1003,\"quantity\":1}],\"transactionid\":\"8817508e-805c-48fb-9cb4-6a1e5a6e71e9\"} and TransactionID: 8817508e-805c-48fb-9cb4-6a1e5a6e71e9\n\nSending message: {\"salesId\":\"6165b92addaf7fc9dd85dad0\",\"status\":\"APPROVED\",\"transactionid\":\"8817508e-805c-48fb-9cb4-6a1e5a6e71e9\"}\n\nRecieving message from queue: {\"salesId\":\"6165b92addaf7fc9dd85dad0\",\"status\":\"APPROVED\",\"transactionid\":\"8817508e-805c-48fb-9cb4-6a1e5a6e71e9\"}\n```\n\n## Endpoint documentation\n\nThe API documentation is present in the file [DOCS](https://github.com/rafaelrok/ms-sales/blob/main/docs/API_DOCS.md).\nAPI endpoints [Collection](https://github.com/rafaelrok/ms-sales/blob/main/docs/MS-Sales.postman_collection.json).\n\n## Deploy Heroku\n\nThe 3 APIs were published on Heroku, the repository that were published are these:\n\n* Auth-API    - https://github.com/vhnegrisoli2018/auth-api (PostgreSQL e Coralogix Logging)\n* Product-API - https://github.com/vhnegrisoli2018/product-api (Coralogix Logging, Cloud MongoDB e CloudAQMP)\n* Sales-API   - https://github.com/vhnegrisoli2018/sales-api (Coralogix Logging Heroku Postgres e CloudAQMP)\n\nAs URL base são:\n\n* Auth-API    - https://microsservicos-auth-api.herokuapp.com/\n* Product-API - https://microsservicos-product-api.herokuapp.com/\n* Sales-API   - https://microsservicos-sales-api.herokuapp.com/\n\n## Tracing with Coralogix Logging and Kibana\n\nCoralogix Logging is a Heroku add-on for adding a status dashboard and viewing logs for applications.\n\nCoralogix Logging dashboard example from Product-API application:\n\n![Dashboard Product-API](https://github.com/rafaelrok/ms-sales/blob/main/docs/Coralogix%20Logging%20Dashboard.png)\n\nOn Heroku, we were able to trace the application through our **TransactionID** header, which is mandatory on all endpoints.\n\nBelow is an example of tracing performed with an order created for **TransactionID** with value **1c75be8c-efbe-44d7-99ea-60564465c77a**.\n\n![Requisição](https://github.com/rafaelrok/ms-sales/blob/main/docs/Exemplo%20Rastreamento%20Requisi%C3%A7%C3%A3o.png)\n\nAfter the request is made, we go to our Kibana provided by Coralogix Logging from the Sales-API application and search the logs by the value **1c75be8c-efbe-44d7-99ea-60564465c77a**:\n\n![Kibana Sales-API](https://github.com/rafaelrok/ms-sales/blob/main/docs/Tracing%20Sales-API.png)\n\nWe can see multiple input and output logs, containing input and output JSON. We can also see that a call was made to the Product-API microservice via HTTP REST, and also a communication via Rabbit message, and we can see these logs being received there in the Product-API application:\n\n![Kibana Product-API](https://github.com/rafaelrok/ms-sales/blob/main/docs/Tracing%20Product-API.png)\n\nWith this, we were able to track all the input and output data of the endpoints, the transaction ID that circulates between them via REST call and via message, facilitating the monitoring of logs of a specific request and, mainly, in the troubleshooting process.\n\n## Docker Commands\n\nBelow will be listed some commands executed during the course to create containers\nfrom the PostgreSQL, MongoDB and RabbitMQ message broker databases:\n\n#### Container Auth-DB\n\n`docker run --name auth-db -p 5432:5432 -e POSTGRES_DB=auth-db -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=123456 postgres:11`\n\n#### Container Product-DB\n\n`docker run --name product-db -p 5433:5432 -e POSTGRES_DB=product-db -e POSTGRES_USER=admin -e POSTGRES_PASSWORD=123456 postgres:11`\n\n#### Container Sales-DB\n\n`docker run --name sales-db -p 27017:27017 -p 28017:28017 -e MONGODB_USER=\"admin\" -e MONGODB_DATABASE=\"sales\" -e MONGODB_PASS=\"123456\" -v  c:/db tutum/mongodb`\n\n#### Conection no Mongoshell\n\n`mongo \"mongodb://admin:123456@localhost:27017/sales\"`\n\n#### Container RabbitMQ\n\n`docker run --name sales_rabbit -p 5672:5672 -p 25676:25676 -p 15672:15672 rabbitmq:3-management`\n\n### Execution docker-compose\n\n`docker-compose up --build`\n\nTo ignore the logs, add the flag`-d`.\n\n\n## Developer\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\n      \u003ca href=\"#\"\u003e\n        \u003cimg src=\"https://avatars.githubusercontent.com/u/8467131?v=4\" width=\"100px;\" alt=\"Foto do Rafael Vieira no GitHub\"/\u003e\u003cbr\u003e\n        \u003csub\u003e\n          \u003cb\u003eRafael Vieira\u003c/b\u003e\n        \u003c/sub\u003e\n      \u003c/a\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ca href=\"https://www.linkedin.com/in/rafaelvieira-s/\"\u003e\n      \u003cimg alt=\"linkedin\" src=\"https://img.shields.io/twitter/url?label=Linkedin\u0026logo=linkedin\u0026style=social\u0026url=https%3A%2F%2Fwww.linkedin.com%2Fin%2Frafaelvieira-s%2F\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://medium.com/@rafael\"\u003e\n      \u003cimg alt=\"medium\" src=\"https://img.shields.io/twitter/url?label=Medium\u0026logo=medium\u0026style=social\u0026url=https%3A%2F%2Fmedium.com%2F%40rafael.\"\u003e\n    \u003c/a\u003e\n    \u003ca href = \"mailto:rafaelrok25@gmail.com\"\u003e\n      \u003cimg alt=\"gmail\" src=\"https://img.shields.io/twitter/url?label=gmail\u0026logo=gmail\u0026style=social\u0026url=https%3A%2F%2Fmail.google.com%2F\"\u003e\n    \u003c/a\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\n## 📝 License\n\nThis project is under license. see the file [LICENSE](./LICENSE) for more details.\n\n##  versions of README\n\n[Português 🇧🇷](./README.md)  |  [English 🇺🇸](./README-en.md) \n\n[⬆ Back to the top](#ms-sales)\u003cbr\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafaelrok%2Fms-sales","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafaelrok%2Fms-sales","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafaelrok%2Fms-sales/lists"}