{"id":16619976,"url":"https://github.com/cepr0/sb-cloud-stream-demo","last_synced_at":"2026-04-29T23:33:00.826Z","repository":{"id":130472471,"uuid":"204219079","full_name":"Cepr0/sb-cloud-stream-demo","owner":"Cepr0","description":"A demonstration of using Spring Cloud Stream with RabbitMQ to transfer messages between micro-services","archived":false,"fork":false,"pushed_at":"2020-03-20T07:34:14.000Z","size":136,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-13T14:46:27.882Z","etag":null,"topics":["blog","microservices","optimistic-locking","postgresql","rabbitmq","reactive","spring-boot","spring-cloud-stream","spring-retry","spring-webflux"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Cepr0.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-24T22:23:06.000Z","updated_at":"2020-03-20T07:34:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"81b41131-85cf-44ff-9cca-1cce15782aa1","html_url":"https://github.com/Cepr0/sb-cloud-stream-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Cepr0/sb-cloud-stream-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cepr0%2Fsb-cloud-stream-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cepr0%2Fsb-cloud-stream-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cepr0%2Fsb-cloud-stream-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cepr0%2Fsb-cloud-stream-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cepr0","download_url":"https://codeload.github.com/Cepr0/sb-cloud-stream-demo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cepr0%2Fsb-cloud-stream-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32448399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"ssl_error","status_checked_at":"2026-04-29T22:10:49.234Z","response_time":110,"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":["blog","microservices","optimistic-locking","postgresql","rabbitmq","reactive","spring-boot","spring-cloud-stream","spring-retry","spring-webflux"],"created_at":"2024-10-12T02:43:12.767Z","updated_at":"2026-04-29T23:33:00.804Z","avatar_url":"https://github.com/Cepr0.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spring Cloud Stream demo\n\nA demonstration of using [Spring Cloud Stream][1] with [RabbitMQ][2] \nto transfer messages between micro-services.\n\n## Used stack\n\n- Java 11\n- Spring Boot\n- Spring Cloud Stream / Spring Cloud Stream Reactive\n- Spring Cloud Stream RabbitMQ Binder\n- Spring Cloud Netflix / Eureka (discovering and load balancing)\n- Spring Web / Web Flux\n- Spring Data JPA / Hibernate\n- Spring Retry\n- Spring Actuator\n- FlyWay\n- Bootstrap \u0026 JavaScript\n- PostgreSQL\n- RabbitMQ\n- Docker / Docker Compose\n\n## Architecture\n\n![architecture](architecture.png) \n\n## Workflow\n\n1. Client 'wants' to buy a product and sends a POST request with specific `productId` \nto `order-service`. By default the `demo-client` sends such requests every 200 ms.\n2. Order service receives 'buy a product' request then creates new order, stores it\nto the local DB, then sends event `OrderCreated` to the message broker.\n3. Product service has subscribed on `OrderCreated` event. When the service received the event \nit tries to 'sell' the product. If the specified product exists and its amount is not zero\nthen the service reduces its amount per unit, and sends the event `OrderCompleted`.\nIf the product not found then the service sends `ProductNotFound` event. If the product amount\nis zero then service sends `ProductEnded` event.\n4. Order service received these events and mark the order respectively: completed or failed.\n5. Supply service has subscribed on `ProductEnded` event. When it received the event\nthen it sends a POST request to `product-service` to restock the product with some value.\n6. Stat service listens to all kind of the events, calculates their rates for the last 10 seconds,\nand sends it with SSE (Server Sent Event) to a subscriber (if there is one) every 1 second.      \n \n## Peculiarities\n\n1. To configure the routes of the events in the message broker the [config application][3] is used.\nIt should be run only once before starting the rest of the services. With Spring Cloud Stream \nthe routes are configured pretty simple in the [Routes interface][4] and the [application properties file][5].     \n2. To avoid locking in the DB of the Product service, when several threads and/or several instances \nof the service will try to modify the amount of the particular product, Optimistic Locking and Spring Retry\nare used.\n\n## Play with the demo\n\nYou should have Java 11, Git, Maven, Docker and Docker Compose be installed.\n\n1. Clone this project and `cd` to its folder\n2. Build the project with maven:\n```shell script\nmvn package\n```\n3. Move to `demo` folder\n```shell script\ncd demo\n``` \n4. Run the environment:\n```shell script\ndocker-compose up -d --build\n```\n5. Open browser on `http://localhost:8080` to see the statistics:\n![demo](demo.gif)\n6. Stop the environment:\n```shell script\ndocker-compose down\n```\n\nYou can increase system load and performance by scaling instances of the services and `demo-client`.\nFor example, scaling `demo-client` and `product-service`:\n```shell script\ndocker-compose up -d --scale demo-client=2 --scale product-service=2\n```\n \n \n[1]: https://spring.io/projects/spring-cloud-stream\n[2]: https://www.rabbitmq.com/\n[3]: config\n[4]: config/src/main/java/io/github/cepr0/demo/config/ConfigApplication.java\n[5]: config/src/main/resources/application.yml","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcepr0%2Fsb-cloud-stream-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcepr0%2Fsb-cloud-stream-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcepr0%2Fsb-cloud-stream-demo/lists"}