LIDANDO COM DESAFIOS DOS MICROSERVIÇOS
COM A STACK SPRING CLOUD NETFLIX
Emmanuel Neri
@emmanuelnerii
EMMANUEL NERI
‣ Mestre em Desenvolvimento de Tecnologia
‣ Desenvolvedor (Java) desde 2010
‣ Professor na FACEC
‣ Líder técnico na Navita
MICROSERVICES
martinfowler.com/articles/microservices.html
COMPUTAÇÃO DISTRIBUÍDA
DESAFIOS
‣ Comunicação
‣ Consistência
‣ Disponibilidade
‣ Monitoramento
‣ Gerenciamento
SPRING + NETFLIX
+
GERENCIAMENTO
SERVICE DISCOVERY
orders:8080
processor:8040 processor:8041
files:8090
EUREKA
‣ Localizador de serviços
‣ Possibilita registro dinâmico
‣ Baseado em serviços REST
‣ Proporciona Health check
EUREKA
EUREKA + SPRING CLOUD
register
renew
30seg
90seg
DISPONIBILIZAÇÃO DAS APLICAÇÕES
Request
PROXY / GATEWAY
PROXY / GATEWAY
Request
ZUUL
‣ Centralização
‣ Gateway
‣ Rotas dinâmicas
‣ ServiceId
‣ Segurança
‣ Spring Cloud Security
ZUUL + SPRING CLOUD
zuul.prefix=/api
zuul.ignored-services=*
zuul.routes.files.path=/files/**
zuul.routes.files.serviceId=FILESAPI
zuul.routes.files.strip-prefix=false
zuul.routes.orders.path=/orders/**
zuul.routes.orders.serviceId=ORDERSAPI
zuul.routes.orders.strip-prefix=false
zuul.routes.receiver.path=/receiver/**
zuul.routes.receiver.serviceId=RECEIVER
zuul.routes.receiver.strip-prefix=false
gateway.properties
ZUUL
Request
ZULL
EUREKA
Retorna lista de aplicações
RIBBON
Pede aplicações
disponíveis
LOAD BALANCER
Request
LOAD BALANCER
RIBBON
‣ Balanceador de carga Client side
‣ Lista das aplicações (ServerList)
‣ Estática
‣ Dinâmica
‣ IPing
‣ IRule
‣ RoundRobinRule
‣ WeightedResponseTimeRule
‣ AvailabilityFilteringRule
COMUNICAÇÃO
FEIGN CLIENTS
@FeignClient(value = "http://localhost:8060", path = "/customers",
name = "customers")
public interface Customers {
@RequestMapping(value = "/customers/document/{cnpj}",
method = RequestMethod.GET)
Customer findByCnpj(@PathVariable("cnpj") String cnpj);
}
FEIGN
‣ Facilitador de Clients HTTP
‣ Logs
‣ Interceptors
‣ Tratamento de erros
‣ Error Handling
‣ Hystrix
‣ Retry
‣ Ribbon
FEIGN + EUREKA
EUREKA
Pede endereço
serviço customers
Retorna endereço do
serviço requisitado
@FeignClient(value = "customers")
public interface Customers {
FALHAS
CIRCUIT BREAKER
HYSTRIX
‣ Impedir propagação de falhas em outros serviços
‣ Aberto, Fechado, Meio Aberto
‣ Recuperação rápida
‣ Fallback
‣ Monitoramento dos serviços
HYSTRIX
@RestController
@RequestMapping(value = "/receiver/orders")
@Slf4j
public class OrderController {
@Autowired
private OrderService orderService;
@HystrixCommand(fallbackMethod = "defaultFallback")
@RequestMapping(value = "/{origin}", method = RequestMethod.POST)
public void receive(
@PathVariable("origin") String origin,
@RequestBody String order) {
orderService.receive(origin, order);
}
private void defaultFallback(String origin, String order) {
log.error("fallback Method - origin: " + origin);
}
}
HYSTRIX
@FeignClient(value = "customers", fallback = CustomersFallBack.class)
public interface Customers {
@RequestMapping(value = "/customers/document/{cnpj}",
method = RequestMethod.GET)
Customer findByCnpj(@PathVariable("cnpj") String cnpj);
}
HYSTRIX
Hystrix Dashboard
MÉTRICAS / DEBUG
TRACE
Request
Response
SLEUTH + ZIPKIN
‣ Spring Cloud Sleuth
‣ Gerar os logs
‣ TraceId , SpanId
‣ REST, Mensageria, Filtros, Agendadores
‣ Zipkin
‣ Interpreta os logs
SLEUTH + ZIPKIN
INFO [ordersApi,49b8420c329b42f7,3dbc2c5800e5669e,true] b.c.e.orders.controller.OrderController
INFO [ordersApi,13ff24ba66af1a00,5c98e5176f8345d9,true] b.c.e.orders.controller.OrderController
Zipkin
CONFIGURAÇÃO
CONFIG SERVER
‣ Servidor de configuração distribuído
‣ Acesso dos arquivos via Rest
‣ Pode armazenar no Git ou SVN
‣ Funcionalidades
‣ Criptografia de configurações
‣ Alterações de properties em runtime
SPRING CLOUD CONFIG
CONFIG SERVER
GIT
OUTROS PROJETOS SPRING CLOUD
‣ Outros recursos
‣ spring-cloud-stream
‣ spring-cloud-task
‣ Alternativas
‣ spring-cloud-zookeeper
‣ spring-cloud-consul
‣ spring-cloud-gateway
NÃO ENGLOBA
‣ Consistência dos dados distribuídas
‣ SAGA
‣ Infraestrutura
‣ Containers
‣ Logs / Monitoramento
‣ ELK - (Elasticsearch/Logstash/Kibana)
RESUMO
Positivo Negativo
Dinamismo Stack Java
Agnóstico de cloud
provider
Custo do dinamismo
Ambiente replicável
https://github.com/emmanuelneri/microservices-spring-cloud
GITHUB/EMMANUELNERI
‣ Configurações distribuídas com Spring Cloud Config
‣ https://emmanuelneri.com.br/2018/07/09/
configuracoes-distribuidas-com-spring-cloud-config/
‣ Clients dinâmicos com Feign e Eureka
‣ https://emmanuelneri.com.br/2018/05/02/criando-
proxy-de-apis-com-spring-cloud-zuul-e-eureka/
‣ Criando proxy de APIs com Spring Cloud, Zuul e Eureka
‣ https://emmanuelneri.com.br/2018/06/05/clients-
dinamicos-com-feign-e-eureka/
EMMANUELNERI.COM.BR
EMMANUEL NERI
emmanuelnerisouza@gmail.com
@emmanuelnerii
www.linkedin.com/in/emmanuelnerisouza
OBRIGADO!
www.emmanuelneri.com.br

Lidando com desafios dos microserviços com a stack Spring Cloud Netflix