no

Microservice - Spring Cloud Configuration Server Using a GIT Store

Go Back to Course Outline Welcome to another video about microservices. Today we will learn about Spring Cloud Configuration and how we...


Go Back to Course Outline

Welcome to another video about microservices. Today we will learn about Spring Cloud Configuration and how we can use it to manage the configuration of our services. As per Spring, Spring Cloud Config provides the server and client-side support for externalized configuration in a distributed system. Basically, what it means is that we can store and versioned the contents of the application property file in GIT. We can also update the configuration at run-time and it is accessible via GIT URI.

For this demonstration, we will need to set up 2 projects, one we should be already familiar with.
  1. Terawarehouse-catalog - this is our catalog microservice
  2. Terawarehouse-config-server - configuration server that reads the configuration from a GIT store

Setting up the Terawarehouse-config-server

  1. Add the spring-cloud-config-server dependency.
  2. Annotate the SpringBootApplication class with @EnableConfigServer.
  3. Configure the application.yml file. For this example, we will point the spring.cloud.config.server.uri to a local git repository (make sure to set it up first).
  4. Run the config server.
  5. Access the configurations via URL: http://localhost:8000/{applicationName}/{profile}.

Setting up the Terawarehouse-catalog project

  1. Add spring-cloud-starter-config dependencies.
  2. Annotate the SpringBoothApplication class with @EnableDiscoveryClient.
  3. In the resource folder, remove the application.yml or properties file and add a bootstrap.properties. In this file, we will be defining the application name as well as the config server URI.
    spring.application.name=catalog
    spring.cloud.config.enabled=true
    spring.cloud.config.uri=http://192.168.1.100:8000
    spring.cloud.config.fail-fast=true
  4. Create a new local git repository where the config server is pointing.
  5. Create a new file with filename equals to the spring.application.name of our microservice project. In this case catalog.
  6. Add all the required properties from the previous video we have. I already created a file named catalog.properties that you can download and paste in your local repository. Make sure to change the database configuration. Commit your changes.
  7. Our configuration should be accessible at http://localhost:8000/catalog/default.
  8. Let’s run the application. It should be accessible at port 8001.
  9. Stop the application.
  10. Let’s create a new profile “integration” with filename catalog-integration.properties and set the port to 8002.
  11. Run the application again and this time it should be available at port 8002.
That should do it for this video. Hoping that what I shared today could be of use to you tomorrow.

References

Repositories


For repositories use:
  • Broodcamp Utils - Release version 0.0.1
  • Broodcamp Commons - Release version 0.0.1
  • Terawarehouse (catalog, config-server) - Tag 24-Microservice_Spring_Cloud_Configuration_Server_Using_a_GIT_Store

Related

coding 3497953406952514390

Post a Comment Default Comments

item