MicroService All In One

MicroService All In One

Good morning to my LinkedIn friend.

Today, I want to share my presentation slides again. It's going to be a long read, but it worth the read.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Scaling problem

?We see we end up wasting our resources. Assuming we only need more sound; we add even the things we do not want to scale.

?Another problem is that we are reliant on one provider. We can’t scale with components from other providers. This will make sense as we go.

Service Oriented Approach

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image


No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

Registry-Service

How to make an app a Registry-Service in SpringBoot ,

First, add the following dependencies in your pom file

<dependency>
????? <groupId>org.springframework.cloud</groupId>
????? <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

<dependency>
??? <groupId>org.springframework.boot</groupId>
??? <artifactId>spring-boot-starter-web/webflux</artifactId>
</dependency>        

If you are in config first mode, add this dependency to enable registry service fetch configurations.

<dependency>
??? <groupId>org.springframework.boot</groupId>
??? <artifactId>spring-boot-starter-config</artifactId>
</dependency>        

Second , let spring know the application is a discovery server from the entry class that bootstraps the application by adding @EnableEurekaServer:?

No alt text provided for this image

Third , configure a discovery server in property file.

No alt text provided for this image

Config-Service

How to make an app a Config-Service in SpringBoot?

Add the following dependencies on maven pom file.

<dependency>
??? <groupId>org.springframework.cloud</groupId>
??? <artifactId>spring-cloud-config-server</artifactId>
</dependency>

<dependency
??? <groupId>org.springframework.boot</groupId>
??? <artifactId>spring-boot-starter-web/webflux</artifactId>
</dependency>        

Spring Cloud Config Server also supports Vault as a backend. If you have stored your secrets and password outside.

<dependency>
??? <groupId>org.springframework.vault</groupId>
??? <artifactId>spring-vault-core</artifactId>
</dependency>        
No alt text provided for this image

1. Within the application

The configurations are part of the config-service, and they are placed in resources folder. Shared is a folder in resources containing configurations for each service.

No alt text provided for this image

2. Within the host machine

The configurations are placed somewhere within the host machine. You can place them in documents, C-Drive, Desktop etc.

No alt text provided for this image

3. GitHub, Bitbucket, Gitlab etc.

The configurations reside in some remote application such as GitHub, Bitbucket etc. If your repo is protected, you will need to provide credentials to authenticate. My GitHub repo is not protected.

No alt text provided for this image

Activate config-service in Java.

You also need to let spring know you want to make the application a config server by adding @EnableConfigServer

No alt text provided for this image

Config-Service

These are the configurations for other micro-services that the config serves. The name of the YML file must be the same as the name specified in the client that fetches its configurations. This enables the configurations service to pick correct configs for each request. Will make a separate article on circuit breaker.

No alt text provided for this image
No alt text provided for this image

Micro-Service-Client

How to make an app a Client in SpringBoot? In this case the client is a config client, meaning client fetches its configurations from the config service, also, the client is eureka client, meaning it registers with discovery service on startup.

<dependency>
??? <groupId>org.springframework.cloud</groupId>
??? <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

<dependency>
??? <groupId>org.springframework.boot</groupId>
??? <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<dependency>
??? <groupId>org.springframework.boot</groupId>
??? <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
??? <groupId>org.springframework.boot</groupId>
??? <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>        

Configurations for a client.

Look at the code snippet below.

No alt text provided for this image

Line 8-9 allows the client to authenticate with the configuration service.

Line 18 fetches configurations from the config server.

Enabling the client.

With the config-service and discovery-service, you must explicitly add annotations @EnableConfigServer and @EnableEurekaServer respectively, but with a client we don’t need any annotation.

Wait a minute! How does Spring know that the app is a config client and/or a eureka client?

On the early versions of Spring Cloud, you had to add @EnableDiscoveryClient to make a service a eureka client. However, the latest versions, not sure which version, you only need to add either eureka or some other implementation in maven pom(class-path), Spring will automatically enable the client. The same goes for config client dependency.

Next article Series 2, I talk about circuit breaker.

As always, if you want to support my work, please subscribe to my YouTube channel below.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了