Creating a Configuration Server
In the previous entry microservices we saw the architecture we are going to use, so now we need to create some projects to implement the architecture, and those projects are:
- Config Server
- Eureka Server
- Api Gateway
- Microservice
Creating and configuring the Config Server
The config server is going to be use for our applications to centralize the configurations, spring cloud can provide us configuration by using a file system or a git repository, in this case we are going to use the second one, letting our microservices to have a externalized configuration, this will give us control when we want to change the configuration of our microservices.
Let's start by creating a project for our config server, to do this, we need to access to: start.spring.io and create a gradle project with only one dependency: config-server like the image below:
Now just click in the button Generate the project
This will download a the project in zip format, you should extract the project and open by using the IDE you want, in my case Intellij, and let's start doing the configurations, the server will be embeded in our spring application by using the annotation @EnableConfigServer that all we need, take a look to the next image:
Another thing we need to do is add the configurations to the application.yml file to give the access to a git repository where the configurations for the microservices:
The previous configurations gonna let us access to the git repository, there are a lot of possibilities using centralized configurations but for now we just going to create a file with the name of the service in the repository, for this example customers.yml in the future we going to create different profiles for our microservices, so we can have configurations for development, testing and production.
At this moment we have the basic configurations to run our application
Obviusly our application shows an error because we did not add any endpoint but it's oke, in the next entries we going to see how the microservices request and get access to their configurations by using the config server we created.
If you want to know more details about entralized configurations please visit:
spring docs
We are going to view those configuration in the next entries.
Thanks for reading, please feel free to let me know any comment
And here are the repositories we are using in this post:
config-server
application-configs
This is getting better every day!