Spring Cloud + Docker
Dependências
Para rodar Eureka (client) e Ribbon (Load Balancer) em um microserviço
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
Para rodar Eureka server (registry | discovery)
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
Dependências
Para rodar o API Gateway (Zuul)
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
Para rodar o servidor de configuração
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
Dependências
Como o Hystrix utiliza o RabbitMQ para se comunicar entre o Circuit breaker e Dashboard (aplicação de monitoração), é necessário utilizar as dependências do RabbitMQ com o Hystrix. Certifique-se que o RabbitMQ está com o apontamento correto senão o Turbine não funcionará.
Para rodar o Hystrix
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-netflix-hystrix-amqp</artifactId>
</dependency>
Dependências (monitor-dashboard)
Para habilitar o hystrix dashboard
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
Para coletar as métricas do hystrix via HTTP
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine</artifactId>
</dependency>
Para coletar as métricas via streaming
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-turbine-amqp</artifactId>
</dependency>
Dependências (tracing-server)
Para habilitar o Zipkin
<dependency>
<groupId>io.zipkin.java</groupId>
<artifactId>zipkin-autoconfigure-ui</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>
</dependency>
Para habilitar o Sleuth
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-sleuth-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
Anotações
Eureka Server (registry | discovery)
@EnableEurekaServer
Config Server
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
Zuul Server (API Gateway)
@EnableZuulProxy
@EnableDiscoveryClient
Habilitar Circuit Breaker
@EnableCircuitBreaker
Habilitar Interfaces Feign
@EnableFeignClients
Docker Commands / Scripts
Build (build-images.sh)
docker build -t registry.vivotools.com.br/config-server ./config-server
Start containers (start-containers.sh)
export APP_CONFIG_DIR=/home/app/jaimail-microservices/config
export APP_LOGGING_DIR=/home/app/jaimail-microservices/logs
docker-compose up -d
Push image to registry (push-images.sh)
docker push registry.vivotools.com.br/config-server
Docker Commands
Stop containers
docker-compose down
Run microservice
docker-compose up config-server -d
Scale
docker-compose scale jaimail-router=3
... e irão surgir novos problemas