Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Distributed version of Spring Petclinic built with Spring Cloud

License

NotificationsYou must be signed in to change notification settings

spring-petclinic/spring-petclinic-microservices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusLicense

This microservices branch was initially derived fromAngularJS version to demonstrate how to split sample Spring application intomicroservices.To achieve that goal, we use Spring Cloud Gateway, Spring Cloud Circuit Breaker, Spring Cloud Config, Micrometer Tracing, Resilience4j, Open Telemetryand the Eureka Service Discovery from theSpring Cloud Netflix technology stack.

Open in GitHub Codespaces

Open in Codeanywhere

Starting services locally without Docker

Every microservice is a Spring Boot application and can be started locally using IDE or../mvnw spring-boot:run command.Please note that supporting services (Config and Discovery Server) must be started before any other application (Customers, Vets, Visits and API).Startup of Tracing server, Admin server, Grafana and Prometheus is optional.If everything goes well, you can access the following services at given location:

You can tell Config Server to use your local Git repository by usingnative Spring profile and settingGIT_REPO environment variable, for example:-Dspring.profiles.active=native -DGIT_REPO=/projects/spring-petclinic-microservices-config

Starting services locally with docker-compose

In order to start entire infrastructure using Docker, you have to build images by executingbash ./mvnw clean install -P buildDockerThis requiresDocker orDocker desktop to be installed and running.

Alternatively you can also build all the images onPodman, which requires Podman or Podman Desktop to be installed and running.

./mvnw clean install -PbuildDocker -Dcontainer.executable=podman

By default, the Docker OCI image is build for anlinux/amd64 platform.For other architectures, you could change it by using the-Dcontainer.platform maven command line argument.For instance, if you target container images for an Apple M2, you could use the command line with thelinux/arm64 architecture:

./mvnw clean install -P buildDocker -Dcontainer.platform="linux/arm64"

Once images are ready, you can start them with a single commanddocker compose up orpodman-compose up.

Containers startup order is coordinated with theservice_healthy condition of the Docker Composedepends-on expressionand thehealthcheck of the service containers.After starting services, it takes a while for API Gateway to be in sync with service registry,so don't be scared of initial Spring Cloud Gateway timeouts. You can track services availability using Eureka dashboardavailable by default athttp://localhost:8761.

Themain branch uses an Eclipse Temurin with Java 17 as Docker base image.

NOTE: Under MacOSX or Windows, make sure that the Docker VM has enough memory to run the microservices. The default settingsare usually not enough and make thedocker-compose up painfully slow.

Starting services locally with docker-compose and Java

If 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 standardnohup java -jar ... command. The logs will be available under${ROOT}/target/nameoftheapp.log.

Each of the java based applications is started with thechaos-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.

Understanding the Spring Petclinic application

See the presentation of the Spring Petclinic Framework version

A blog post introducing the Spring Petclinic Microsevices (french language)

You can then access petclinic here:http://localhost:8080/

Microservices Overview

This project consists of several microservices:

  • Customers Service: Manages customer data.
  • Vets Service: Handles information about veterinarians.
  • Visits Service: Manages pet visit records.
  • GenAI Service: Provides a chatbot interface to the application.
  • API Gateway: Routes client requests to the appropriate services.
  • Config Server: Centralized configuration management for all services.
  • Discovery Server: Eureka-based service registry.

Each service has its own specific role and communicates via REST APIs.

Spring Petclinic Microservices screenshot

Architecture diagram of the Spring Petclinic Microservices

Spring Petclinic Microservices architecture

Integrating the Spring AI Chatbot

Spring 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:

  1. Please list the owners that come to the clinic.
  2. Are there any vets that specialize in surgery?
  3. Is there an owner named Betty?
  4. Which owners have dogs?
  5. Add a dog for Betty. Its name is Moopsie.
  6. Create a new owner.

Screenshot of the chat dialog

Thisspring-petlinic-genai-service microservice currently supportsOpenAI (default) orAzure's OpenAI as the LLM provider.In order to start the microservice, perform the following steps:

  1. Decide which provider you want to use. By default, thespring-ai-openai-spring-boot-starter dependency is enabled.You can change it tospring-ai-azure-openai-spring-boot-starterin thepom.xml.
  2. Create an OpenAI API key or a Azure OpenAI resource in your Azure Portal.Refer to theOpenAI's quickstart orAzure's documentation for further information on how to obtain these.You only need to populate the provider you're using - either openai, or azure-openai.If you don't have your own OpenAI API key, don't worry!You can temporarily use thedemo key, which OpenAI provides free of charge for demonstration purposes.Thisdemo key has a quota, is limited to thegpt-4o-mini model, and is intended solely for demonstration use.With your own OpenAI account, you can test thegpt-4o model by modifying thedeployment-name property of theapplication.yml file.
  3. Export your API keys and endpoint as environment variables:
    • either OpenAI:
    export OPENAI_API_KEY="your_api_key_here"
    • or Azure OpenAI:
    export AZURE_OPENAI_ENDPOINT="https://your_resource.openai.azure.com"export AZURE_OPENAI_KEY="your_api_key_here"

In case you find a bug/suggested improvement for Spring Petclinic Microservices

Our issue tracker is available here:https://github.com/spring-petclinic/spring-petclinic-microservices/issues

Database configuration

In its default configuration, Petclinic uses an in-memory database (HSQLDB) which gets populated at startup with data.A similar setup is provided for MySql in case a persistent database configuration is needed.Dependency for Connector/J, the MySQL JDBC driver is already included in thepom.xml files.

Start a MySql database

You may start a MySql database with docker:

docker run -e MYSQL_ROOT_PASSWORD=petclinic -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:8.4.5

or 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/

Use the Spring 'mysql' profile

To use a MySQL database, you have to start 3 microservices (visits-service,customers-service andvets-services)with themysql Spring profile. Add the--spring.profiles.active=mysql as program argument.

By default, at startup, database schema will be created and data will be populated.You may also manually create the PetClinic database and data by executing the"db/mysql/{schema,data}.sql" scripts of each 3 microservices.In theapplication.yml of theConfiguration repository, set theinitialization-mode tonever.

If you are running the microservices with Docker, you have to add themysql profile into the (Dockerfile)[docker/Dockerfile]:

ENV SPRING_PROFILES_ACTIVE docker,mysql

In themysql section of theapplication.yml from theConfiguration repository, you have to changethe host and port of your MySQL JDBC connection string.

Custom metrics monitoring

Grafana and Prometheus are included in thedocker-compose.yml configuration, and the public facing applicationshave been instrumented withMicroMeter to collect JVM and custom business metrics.

A JMeter load testing script is available to stress the application and generate metrics:petclinic_test_plan.jmx

Grafana metrics dashboard

Using Prometheus

Using Grafana with Prometheus

Custom metrics

Spring Boot registers a lot number of core metrics: JVM, CPU, Tomcat, Logback...The Spring Boot auto-configuration enables the instrumentation of requests handled by Spring MVC.All those three REST controllersOwnerResource,PetResource andVisitResource have been instrumented by the@Timed Micrometer annotation at class level.

  • customers-service application has the following custom metrics enabled:
    • @Timed:petclinic.owner
    • @Timed:petclinic.pet
  • visits-service application has the following custom metrics enabled:
    • @Timed:petclinic.visit

Looking for something in particular?

Spring Cloud componentsResources
Configuration serverConfig server properties andConfiguration repository
Service DiscoveryEureka server andService discovery client
API GatewaySpring Cloud Gateway starter andRouting configuration
Docker ComposeSpring Boot with Docker guide anddocker-compose file
Circuit BreakerResilience4j fallback method
Grafana / Prometheus MonitoringMicrometer implementation,Spring Boot Actuator Production Ready Metrics
Front-end moduleFiles
Node and NPMThe frontend-maven-plugin plugin downloads/installs Node and NPM locally then runs Bower and Gulp
BowerJavaScript libraries are defined by the manifest file bower.json
GulpTasks automated by Gulp: minify CSS and JS, generate CSS from LESS, copy other static resources
Angular JSapp.js, controllers and templates

Pushing to a Docker registry

Docker images forlinux/amd64 andlinux/arm64 platforms have been published into DockerHubin thespringcommunity organization.You can pull an image:

docker pull springcommunity/spring-petclinic-config-server

You may prefer to build then push images to your own Docker registry.

Choose your Docker registry

You need to define your target Docker registry.Make sure you're already logged in by runningdocker login <endpoint> ordocker login if you're just targeting Docker hub.

Setup theREPOSITORY_PREFIX env variable to target your Docker registry.If you're targeting Docker hub, simple provide your username, for example:

export REPOSITORY_PREFIX=springcommunity

For other Docker registries, provide the full URL to your repository, for example:

export REPOSITORY_PREFIX=harbor.myregistry.com/petclinic

To push Docker image for thelinux/amd64 and thelinux/arm64 platform to your own registry, please use the command line:

mvn clean install -Dmaven.test.skip -P buildDocker -Ddocker.image.prefix=${REPOSITORY_PREFIX} -Dcontainer.build.extraarg="--push" -Dcontainer.platform="linux/amd64,linux/arm64"

Thescripts/pushImages.sh andscripts/tagImages.sh shell scripts could also be used once you build your image with thebuildDocker maven profile.Thescripts/tagImages.sh requires to declare theVERSION env variable.

Compiling the CSS

There is apetclinic.css inspring-petclinic-api-gateway/src/main/resources/static/css.It was generated from thepetclinic.scss source, combined with theBootstrap library.If you make changes to thescss, or upgrade Bootstrap, you will need to re-compile the CSS resourcesusing the Maven profilecss of thespring-petclinic-api-gatewaymodule.

cd spring-petclinic-api-gatewaymvn generate-resources -P css

Interesting Spring Petclinic forks

The Spring Petclinicmain branch in the mainspring-projectsGitHub org is the "canonical" implementation, currently based on Spring Boot and Thymeleaf.

Thisspring-petclinic-microservices project is one of theseveral forkshosted in a special GitHub org:spring-petclinic.If you have a special interest in a different technology stackthat could be used to implement the Pet Clinic then please join the community there.

Contributing

Theissue tracker is the preferred channel for bug reports, features requests and submitting pull requests.

For pull requests, editor preferences are available in theeditor config for easy use in common text editors. Read more and download plugins athttp://editorconfig.org.

Supported by

JetBrains logo


[8]ページ先頭

©2009-2025 Movatter.jp