{"id":14972026,"url":"https://github.com/spring-petclinic/spring-petclinic-microservices","last_synced_at":"2025-05-13T20:17:56.514Z","repository":{"id":37753406,"uuid":"73559008","full_name":"spring-petclinic/spring-petclinic-microservices","owner":"spring-petclinic","description":"Distributed version of Spring Petclinic built with Spring Cloud","archived":false,"fork":false,"pushed_at":"2025-04-27T17:31:36.000Z","size":8017,"stargazers_count":1832,"open_issues_count":9,"forks_count":2375,"subscribers_count":81,"default_branch":"main","last_synced_at":"2025-04-28T11:57:00.193Z","etag":null,"topics":["chaos-monkey","docker","eureka","grafana","hystrix","micrometer","microservices","opentelemetry","prometheus","resilience4j","ribbon","spring-boot-admin","spring-cloud","zipkin"],"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/spring-petclinic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2016-11-12T14:57:30.000Z","updated_at":"2025-04-28T08:07:00.000Z","dependencies_parsed_at":"2024-01-13T22:23:30.005Z","dependency_job_id":"4425acb9-89d2-46a0-932e-0102a6140f75","html_url":"https://github.com/spring-petclinic/spring-petclinic-microservices","commit_stats":{"total_commits":648,"total_committers":46,"mean_commits":14.08695652173913,"dds":0.683641975308642,"last_synced_commit":"06a9bac5cb26584d23826688a5cddcb77fc4bbf3"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spring-petclinic%2Fspring-petclinic-microservices","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spring-petclinic%2Fspring-petclinic-microservices/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spring-petclinic%2Fspring-petclinic-microservices/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spring-petclinic%2Fspring-petclinic-microservices/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spring-petclinic","download_url":"https://codeload.github.com/spring-petclinic/spring-petclinic-microservices/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254020658,"owners_count":22000757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["chaos-monkey","docker","eureka","grafana","hystrix","micrometer","microservices","opentelemetry","prometheus","resilience4j","ribbon","spring-boot-admin","spring-cloud","zipkin"],"created_at":"2024-09-24T13:46:13.887Z","updated_at":"2025-05-13T20:17:56.496Z","avatar_url":"https://github.com/spring-petclinic.png","language":"Java","funding_links":[],"categories":["13. Examples and Sandbox's","Complex Apps (4+ independent services/apps in solution)"],"sub_categories":["Anomalies Detection"],"readme":"# Distributed version of the Spring PetClinic Sample Application built with Spring Cloud and Spring AI\n\n[![Build Status](https://github.com/spring-petclinic/spring-petclinic-microservices/actions/workflows/maven-build.yml/badge.svg)](https://github.com/spring-petclinic/spring-petclinic-microservices/actions/workflows/maven-build.yml)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\nThis microservices branch was initially derived from [AngularJS version](https://github.com/spring-petclinic/spring-petclinic-angular1) to demonstrate how to split sample Spring application into [microservices](http://www.martinfowler.com/articles/microservices.html).\nTo achieve that goal, we use Spring Cloud Gateway, Spring Cloud Circuit Breaker, Spring Cloud Config, Micrometer Tracing, Resilience4j, Open Telemetry \nand the Eureka Service Discovery from the [Spring Cloud Netflix](https://github.com/spring-cloud/spring-cloud-netflix) technology stack.\n\n[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/spring-petclinic/spring-petclinic-microservices)\n\n[![Open in Codeanywhere](https://codeanywhere.com/img/open-in-codeanywhere-btn.svg)](https://app.codeanywhere.com/#https://github.com/spring-petclinic/spring-petclinic-microservices)\n\n## Starting services locally without Docker\n\nEvery microservice is a Spring Boot application and can be started locally using IDE or `../mvnw spring-boot:run` command.\nPlease note that supporting services (Config and Discovery Server) must be started before any other application (Customers, Vets, Visits and API).\nStartup of Tracing server, Admin server, Grafana and Prometheus is optional.\nIf everything goes well, you can access the following services at given location:\n* Discovery Server - http://localhost:8761\n* Config Server - http://localhost:8888\n* AngularJS frontend (API Gateway) - http://localhost:8080\n* Customers, Vets, Visits and GenAI Services - random port, check Eureka Dashboard \n* Tracing Server (Zipkin) - http://localhost:9411/zipkin/ (we use [openzipkin](https://github.com/openzipkin/zipkin/tree/main/zipkin-server))\n* Admin Server (Spring Boot Admin) - http://localhost:9090\n* Grafana Dashboards - http://localhost:3000\n* Prometheus - http://localhost:9091\n\nYou can tell Config Server to use your local Git repository by using `native` Spring profile and setting\n`GIT_REPO` environment variable, for example:\n`-Dspring.profiles.active=native -DGIT_REPO=/projects/spring-petclinic-microservices-config`\n\n## Starting services locally with docker-compose\nIn order to start entire infrastructure using Docker, you have to build images by executing\n``bash\n./mvnw clean install -P buildDocker\n``\nThis requires `Docker` or `Docker desktop` to be installed and running.\n\nAlternatively you can also build all the images on `Podman`, which requires Podman or Podman Desktop to be installed and running.\n```bash\n./mvnw clean install -PbuildDocker -Dcontainer.executable=podman\n```\nBy default, the Docker OCI image is build for an `linux/amd64` platform.\nFor other architectures, you could change it by using the `-Dcontainer.platform` maven command line argument.\nFor instance, if you target container images for an Apple M2, you could use the command line with the `linux/arm64` architecture:\n```bash\n./mvnw clean install -P buildDocker -Dcontainer.platform=\"linux/arm64\"\n```\n\nOnce images are ready, you can start them with a single command\n`docker compose up` or `podman-compose up`. \n\nContainers startup order is coordinated with the `service_healthy` condition of the Docker Compose [depends-on](https://github.com/compose-spec/compose-spec/blob/main/spec.md#depends_on) expression \nand the [healthcheck](https://github.com/compose-spec/compose-spec/blob/main/spec.md#healthcheck) of the service containers. \nAfter starting services, it takes a while for API Gateway to be in sync with service registry,\nso don't be scared of initial Spring Cloud Gateway timeouts. You can track services availability using Eureka dashboard\navailable by default at http://localhost:8761.\n\nThe `main` branch uses an Eclipse Temurin with Java 17 as Docker base image.\n\n*NOTE: Under MacOSX or Windows, make sure that the Docker VM has enough memory to run the microservices. The default settings\nare usually not enough and make the `docker-compose up` painfully slow.*\n\n\n## Starting services locally with docker-compose and Java\nIf you experience issues with running the system via docker-compose you can try running the `./scripts/run_all.sh` script that will start the infrastructure services via docker-compose and all the Java based applications via standard `nohup java -jar ...` command. The logs will be available under `${ROOT}/target/nameoftheapp.log`. \n\nEach of the java based applications is started with the `chaos-monkey` profile in order to interact with Spring Boot Chaos Monkey. You can check out the (README)[scripts/chaos/README.md] for more information about how to use the `./scripts/chaos/call_chaos.sh` helper script to enable assaults.\n\n## Understanding the Spring Petclinic application\n\n[See the presentation of the Spring Petclinic Framework version](http://fr.slideshare.net/AntoineRey/spring-framework-petclinic-sample-application)\n\n[A blog post introducing the Spring Petclinic Microsevices](http://javaetmoi.com/2018/10/architecture-microservices-avec-spring-cloud/) (french language)\n\nYou can then access petclinic here: http://localhost:8080/\n\n## Microservices Overview\n\nThis project consists of several microservices:\n- **Customers Service**: Manages customer data.\n- **Vets Service**: Handles information about veterinarians.\n- **Visits Service**: Manages pet visit records.\n- **GenAI Service**: Provides a chatbot interface to the application.\n- **API Gateway**: Routes client requests to the appropriate services.\n- **Config Server**: Centralized configuration management for all services.\n- **Discovery Server**: Eureka-based service registry.\n\nEach service has its own specific role and communicates via REST APIs.\n\n\n![Spring Petclinic Microservices screenshot](docs/application-screenshot.png)\n\n\n**Architecture diagram of the Spring Petclinic Microservices**\n\n![Spring Petclinic Microservices architecture](docs/microservices-architecture-diagram.jpg)\n\n## Integrating the Spring AI Chatbot\n\nSpring Petclinic integrates a Chatbot that allows you to interact with the application in a natural language. Here are some examples of what you could ask:\n\n1. Please list the owners that come to the clinic.\n2. Are there any vets that specialize in surgery?\n3. Is there an owner named Betty?\n4. Which owners have dogs?\n5. Add a dog for Betty. Its name is Moopsie.\n6. Create a new owner.\n\n![Screenshot of the chat dialog](docs/spring-ai.png)\n\nThis `spring-petlinic-genai-service` microservice currently supports **OpenAI** (default) or **Azure's OpenAI** as the LLM provider.\nIn order to start the microservice, perform the following steps:\n\n1. Decide which provider you want to use. By default, the `spring-ai-openai-spring-boot-starter` dependency is enabled. \n   You can change it to `spring-ai-azure-openai-spring-boot-starter`in the `pom.xml`.\n2. Create an OpenAI API key or a Azure OpenAI resource in your Azure Portal.\n   Refer to the [OpenAI's quickstart](https://platform.openai.com/docs/quickstart) or [Azure's documentation](https://learn.microsoft.com/en-us/azure/ai-services/openai/) for further information on how to obtain these.\n   You only need to populate the provider you're using - either openai, or azure-openai.\n   If you don't have your own OpenAI API key, don't worry!\n   You can temporarily use the `demo` key, which OpenAI provides free of charge for demonstration purposes.\n   This `demo` key has a quota, is limited to the `gpt-4o-mini` model, and is intended solely for demonstration use.\n   With your own OpenAI account, you can test the `gpt-4o` model by modifying the `deployment-name` property of the `application.yml` file.\n3. Export your API keys and endpoint as environment variables:\n    * either OpenAI:\n    ```bash\n    export OPENAI_API_KEY=\"your_api_key_here\"\n    ```\n    * or Azure OpenAI:\n    ```bash\n    export AZURE_OPENAI_ENDPOINT=\"https://your_resource.openai.azure.com\"\n    export AZURE_OPENAI_KEY=\"your_api_key_here\"\n    ```\n\n## In case you find a bug/suggested improvement for Spring Petclinic Microservices\n\nOur issue tracker is available here: https://github.com/spring-petclinic/spring-petclinic-microservices/issues\n\n## Database configuration\n\nIn its default configuration, Petclinic uses an in-memory database (HSQLDB) which gets populated at startup with data.\nA similar setup is provided for MySql in case a persistent database configuration is needed.\nDependency for Connector/J, the MySQL JDBC driver is already included in the `pom.xml` files.\n\n### Start a MySql database\n\nYou may start a MySql database with docker:\n\n```\ndocker run -e MYSQL_ROOT_PASSWORD=petclinic -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:8.4.5\n```\nor download and install the MySQL database (e.g., MySQL Community Server 8.4.5 LTS), which can be found here: https://dev.mysql.com/downloads/\n\n### Use the Spring 'mysql' profile\n\nTo use a MySQL database, you have to start 3 microservices (`visits-service`, `customers-service` and `vets-services`)\nwith the `mysql` Spring profile. Add the `--spring.profiles.active=mysql` as program argument.\n\nBy default, at startup, database schema will be created and data will be populated.\nYou may also manually create the PetClinic database and data by executing the `\"db/mysql/{schema,data}.sql\"` scripts of each 3 microservices. \nIn the `application.yml` of the [Configuration repository], set the `initialization-mode` to `never`.\n\nIf you are running the microservices with Docker, you have to add the `mysql` profile into the (Dockerfile)[docker/Dockerfile]:\n```\nENV SPRING_PROFILES_ACTIVE docker,mysql\n```\nIn the `mysql section` of the `application.yml` from the [Configuration repository], you have to change \nthe host and port of your MySQL JDBC connection string. \n\n## Custom metrics monitoring\n\nGrafana and Prometheus are included in the `docker-compose.yml` configuration, and the public facing applications\nhave been instrumented with [MicroMeter](https://micrometer.io) to collect JVM and custom business metrics.\n\nA JMeter load testing script is available to stress the application and generate metrics: [petclinic_test_plan.jmx](spring-petclinic-api-gateway/src/test/jmeter/petclinic_test_plan.jmx)\n\n![Grafana metrics dashboard](docs/grafana-custom-metrics-dashboard.png)\n\n### Using Prometheus\n\n* Prometheus can be accessed from your local machine at http://localhost:9091\n\n### Using Grafana with Prometheus\n\n* An anonymous access and a Prometheus datasource are setup.\n* A `Spring Petclinic Metrics` Dashboard is available at the URL http://localhost:3000/d/69JXeR0iw/spring-petclinic-metrics.\nYou will find the JSON configuration file here: [docker/grafana/dashboards/grafana-petclinic-dashboard.json]().\n* You may create your own dashboard or import the [Micrometer/SpringBoot dashboard](https://grafana.com/dashboards/4701) via the Import Dashboard menu item.\nThe id for this dashboard is `4701`.\n\n### Custom metrics\nSpring Boot registers a lot number of core metrics: JVM, CPU, Tomcat, Logback... \nThe Spring Boot auto-configuration enables the instrumentation of requests handled by Spring MVC.\nAll those three REST controllers `OwnerResource`, `PetResource` and `VisitResource` have been instrumented by the `@Timed` Micrometer annotation at class level.\n\n* `customers-service` application has the following custom metrics enabled:\n  * @Timed: `petclinic.owner`\n  * @Timed: `petclinic.pet`\n* `visits-service` application has the following custom metrics enabled:\n  * @Timed: `petclinic.visit`\n\n## Looking for something in particular?\n\n| Spring Cloud components         | Resources  |\n|---------------------------------|------------|\n| Configuration server            | [Config server properties](spring-petclinic-config-server/src/main/resources/application.yml) and [Configuration repository] |\n| Service Discovery               | [Eureka server](spring-petclinic-discovery-server) and [Service discovery client](spring-petclinic-vets-service/src/main/java/org/springframework/samples/petclinic/vets/VetsServiceApplication.java) |\n| API Gateway                     | [Spring Cloud Gateway starter](spring-petclinic-api-gateway/pom.xml) and [Routing configuration](/spring-petclinic-api-gateway/src/main/resources/application.yml) |\n| Docker Compose                  | [Spring Boot with Docker guide](https://spring.io/guides/gs/spring-boot-docker/) and [docker-compose file](docker-compose.yml) |\n| Circuit Breaker                 | [Resilience4j fallback method](spring-petclinic-api-gateway/src/main/java/org/springframework/samples/petclinic/api/boundary/web/ApiGatewayController.java)  |\n| Grafana / Prometheus Monitoring | [Micrometer implementation](https://micrometer.io/), [Spring Boot Actuator Production Ready Metrics] |\n\n|  Front-end module | Files |\n|-------------------|-------|\n| Node and NPM      | [The frontend-maven-plugin plugin downloads/installs Node and NPM locally then runs Bower and Gulp](spring-petclinic-ui/pom.xml)  |\n| Bower             | [JavaScript libraries are defined by the manifest file bower.json](spring-petclinic-ui/bower.json)  |\n| Gulp              | [Tasks automated by Gulp: minify CSS and JS, generate CSS from LESS, copy other static resources](spring-petclinic-ui/gulpfile.js)  |\n| Angular JS        | [app.js, controllers and templates](spring-petclinic-ui/src/scripts/)  |\n\n## Pushing to a Docker registry\n\nDocker images for `linux/amd64` and `linux/arm64` platforms have been published into DockerHub \nin the [springcommunity](https://hub.docker.com/u/springcommunity) organization.\nYou can pull an image:\n```bash\ndocker pull springcommunity/spring-petclinic-config-server\n```\nYou may prefer to build then push images to your own Docker registry.\n\n### Choose your Docker registry\n\nYou need to define your target Docker registry.\nMake sure you're already logged in by running `docker login \u003cendpoint\u003e` or `docker login` if you're just targeting Docker hub.\n\nSetup the `REPOSITORY_PREFIX` env variable to target your Docker registry.\nIf you're targeting Docker hub, simple provide your username, for example:\n```bash\nexport REPOSITORY_PREFIX=springcommunity\n```\n\nFor other Docker registries, provide the full URL to your repository, for example:\n```bash\nexport REPOSITORY_PREFIX=harbor.myregistry.com/petclinic\n```\n\nTo push Docker image for the `linux/amd64` and the `linux/arm64` platform to your own registry, please use the command line:\n```bash\nmvn clean install -Dmaven.test.skip -P buildDocker -Ddocker.image.prefix=${REPOSITORY_PREFIX} -Dcontainer.build.extraarg=\"--push\" -Dcontainer.platform=\"linux/amd64,linux/arm64\"\n```\n\nThe `scripts/pushImages.sh` and `scripts/tagImages.sh` shell scripts could also be used once you build your image with the `buildDocker` maven profile.\nThe `scripts/tagImages.sh` requires to declare the `VERSION` env variable.\n\n## Compiling the CSS\n\nThere is a `petclinic.css` in `spring-petclinic-api-gateway/src/main/resources/static/css`.\nIt was generated from the `petclinic.scss` source, combined with the [Bootstrap](https://getbootstrap.com/) library.\nIf you make changes to the `scss`, or upgrade Bootstrap, you will need to re-compile the CSS resources\nusing the Maven profile `css` of the `spring-petclinic-api-gateway`module.\n```bash\ncd spring-petclinic-api-gateway\nmvn generate-resources -P css\n```\n\n## Interesting Spring Petclinic forks\n\nThe Spring Petclinic `main` branch in the main [spring-projects](https://github.com/spring-projects/spring-petclinic)\nGitHub org is the \"canonical\" implementation, currently based on Spring Boot and Thymeleaf.\n\nThis [spring-petclinic-microservices](https://github.com/spring-petclinic/spring-petclinic-microservices/) project is one of the [several forks](https://spring-petclinic.github.io/docs/forks.html) \nhosted in a special GitHub org: [spring-petclinic](https://github.com/spring-petclinic).\nIf you have a special interest in a different technology stack\nthat could be used to implement the Pet Clinic then please join the community there.\n\n\n## Contributing\n\nThe [issue tracker](https://github.com/spring-petclinic/spring-petclinic-microservices/issues) is the preferred channel for bug reports, features requests and submitting pull requests.\n\nFor pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at \u003chttp://editorconfig.org\u003e.\n\n\n[Configuration repository]: https://github.com/spring-petclinic/spring-petclinic-microservices-config\n[Spring Boot Actuator Production Ready Metrics]: https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-metrics.html\n\n## Supported by\n\n[![JetBrains logo](https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg)](https://jb.gg/OpenSourceSupport)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspring-petclinic%2Fspring-petclinic-microservices","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspring-petclinic%2Fspring-petclinic-microservices","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspring-petclinic%2Fspring-petclinic-microservices/lists"}