Microservice architecture with
Spring Cloud and Netflix OSS
Who am I?
Denis Danov
Software Engineer
&
Consultant at Dreamix Ltd.
www.dreamix.eu
Microservice architecture introduction
o What is a microservice?
o How to develop microservices?
o Microservice properties
n Small and singly focused
n Loosly-coupled and simple
n Technology agnostic
n Independent deployable units
o Distributed system
n Patterns common to all distributed systems
lead to boilerplate code
n configuration management, service
discovery, circuit breakers, intelligent
routing, messaging service etc.
o Spring Boot
n Simple infrastructure
n Few dependencies
n REST integrated
n Messaging support
n Uniform operations and metrics
n Logging
n Simple deployment
o Spring Cloud
n Distributed/versioned
configuration
n Service registration and
discovery
n Routing
n Service-to-service calls
n Load balancing
n Circuit Breakers
n Distributed messaging
o Netflix OSS
n Archaius
n Eureka
n Zuul
n Feign
n Ribbon
n Hystrix
Simple application
Production ready
o Having your code done is not the
same as production ready.
o You have to think how to monitor
your application metric in
production.
o Spring Actuator exposes
applciation metric which can be
sent and displayed from another
tool such as Graphite
Architecture components
We have our microservice now it
needs a good environment to live in
Spring Cloud Dependency
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-
dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
o The 12 Factor manifesto talks
about externalizing that which
changes from one environment to
another from the application itself
o Cloud Config Server takes care to
centralize, externalize, and
dynamically update application
configuration.
Configuration
Key points
o Server:
n Dependency:
spring-cloud-config-server
n Annotation:
@EnableConfigServer
@SpringBootApplication
public class CloudConfigApplication
o Client:
n Dependency:
spring-cloud-starter-config
n Properties:
Specify config server address
o In the cloud, services are often
ephemeral and it's important to
be able to talk to these services
abstractly, without worrying about
the host and ports for these
services.
o Eureka
Service Discovery
Key points
o Server:
n Dependency:
spring-cloud-starter-eureka-server
n Annotation:
@EnableEurekaServer
@SpringBootApplication
public class DiscoveryApplication
o Client:
n Dependency:
spring-cloud-starter-eureka
n Annotation:
@EnableDiscoveryClient
n Properties:
Specify eureka server address
Change config address to service name
o Edge services sit as intermediaries
between the clients and the service.
o Proxy requests from an edge-service
to mid-tier services with a
microproxy.
o API gateways are used whenever a
client - like a mobile phone or HTML5
client - requires API translation.
o Zuul, Ribbon, Spring Retry
Edge Services: API gateways
Key points
o Server:
n Dependency:
spring-cloud-starter-zuul - proxy
spring-cloud-starter-feign - HTTP REST client
n Annotation:
@EnableZuulProxy
@EnableDiscoveryClient
@SpringBootApplication
public class ApiGatewayApplication
@FeignClient("team-mservice")
public interface CompanyClient
o Log aggregation and analysis.
o Essential part of microservice
environment.
o ELK=Elastic+Logstash+Kibana
o Logback
Logging
o Distributed tracing lets us trace
the path of a request from one
service to another.
o It's very useful in understanding
where a failure is occurring in a
complex chain of calls.
o Zipkin server and Sleuth
Distributed tracing
Key points
o Server:
n Dependency:
zipkin-server
zipkin-autoconfigure-ui
n Annotation:
@EnableZipkinServer
o Client:
n Dependency:
spring-cloud-starter-sleuth
spring-cloud-starter-zipkin
n Configuration:
ZipkinSpanReporter Bean
o We often assume that services
will always be up and responding
to requests.
o We need to be a bit more
defensive in any code that
connects to other services.
o There have to be a usefull fallback
mechanism
o Hystrix
Resilience, circuit-breaker
Key points
o Server:
n Dependency:
spring-cloud-starter-hystrix-dashboard
n Annotation:
@EnableHystrixDashboard
o Client:
n Dependency:
spring-cloud-starter-hystrix
spring-boot-starter-actuator
n Configuration:
@HystrixCommand(fallbackMethod = "fallback")
o All this is a long process of
discovery.
o Capture all this in your Maven
starter with auto-configuration
o It is not needed to reinvent the
wheel.
o There are different log
aggregation and analysis
alternatives:
n EKK=Elastic+Kinesis+Kibana (AWS)
n Graylog - nice alerts
Alternatives
Kubernetes/Kubeflix
o Language and technology agnostic
o Reduces the need for:
n discovery service
n client-side loadbalancing
n edge-service proxy
JHipster microservices
Resources
o https://github.com/dndanoff/microservices
o 12 Factor Application
o Spring Cloud Project
o Spring Cloud Docs
Microservices with Spring Cloud and Netflix OSS

Microservices with Spring Cloud and Netflix OSS

  • 1.
  • 2.
    Who am I? DenisDanov Software Engineer & Consultant at Dreamix Ltd. www.dreamix.eu
  • 5.
  • 6.
    o What isa microservice? o How to develop microservices?
  • 7.
    o Microservice properties nSmall and singly focused n Loosly-coupled and simple n Technology agnostic n Independent deployable units o Distributed system n Patterns common to all distributed systems lead to boilerplate code n configuration management, service discovery, circuit breakers, intelligent routing, messaging service etc.
  • 8.
    o Spring Boot nSimple infrastructure n Few dependencies n REST integrated n Messaging support n Uniform operations and metrics n Logging n Simple deployment
  • 9.
    o Spring Cloud nDistributed/versioned configuration n Service registration and discovery n Routing n Service-to-service calls n Load balancing n Circuit Breakers n Distributed messaging o Netflix OSS n Archaius n Eureka n Zuul n Feign n Ribbon n Hystrix
  • 10.
  • 11.
    Production ready o Havingyour code done is not the same as production ready. o You have to think how to monitor your application metric in production. o Spring Actuator exposes applciation metric which can be sent and displayed from another tool such as Graphite
  • 12.
    Architecture components We haveour microservice now it needs a good environment to live in
  • 13.
  • 14.
    o The 12Factor manifesto talks about externalizing that which changes from one environment to another from the application itself o Cloud Config Server takes care to centralize, externalize, and dynamically update application configuration. Configuration
  • 16.
    Key points o Server: nDependency: spring-cloud-config-server n Annotation: @EnableConfigServer @SpringBootApplication public class CloudConfigApplication o Client: n Dependency: spring-cloud-starter-config n Properties: Specify config server address
  • 17.
    o In thecloud, services are often ephemeral and it's important to be able to talk to these services abstractly, without worrying about the host and ports for these services. o Eureka Service Discovery
  • 19.
    Key points o Server: nDependency: spring-cloud-starter-eureka-server n Annotation: @EnableEurekaServer @SpringBootApplication public class DiscoveryApplication o Client: n Dependency: spring-cloud-starter-eureka n Annotation: @EnableDiscoveryClient n Properties: Specify eureka server address Change config address to service name
  • 20.
    o Edge servicessit as intermediaries between the clients and the service. o Proxy requests from an edge-service to mid-tier services with a microproxy. o API gateways are used whenever a client - like a mobile phone or HTML5 client - requires API translation. o Zuul, Ribbon, Spring Retry Edge Services: API gateways
  • 22.
    Key points o Server: nDependency: spring-cloud-starter-zuul - proxy spring-cloud-starter-feign - HTTP REST client n Annotation: @EnableZuulProxy @EnableDiscoveryClient @SpringBootApplication public class ApiGatewayApplication @FeignClient("team-mservice") public interface CompanyClient
  • 23.
    o Log aggregationand analysis. o Essential part of microservice environment. o ELK=Elastic+Logstash+Kibana o Logback Logging
  • 25.
    o Distributed tracinglets us trace the path of a request from one service to another. o It's very useful in understanding where a failure is occurring in a complex chain of calls. o Zipkin server and Sleuth Distributed tracing
  • 27.
    Key points o Server: nDependency: zipkin-server zipkin-autoconfigure-ui n Annotation: @EnableZipkinServer o Client: n Dependency: spring-cloud-starter-sleuth spring-cloud-starter-zipkin n Configuration: ZipkinSpanReporter Bean
  • 28.
    o We oftenassume that services will always be up and responding to requests. o We need to be a bit more defensive in any code that connects to other services. o There have to be a usefull fallback mechanism o Hystrix Resilience, circuit-breaker
  • 30.
    Key points o Server: nDependency: spring-cloud-starter-hystrix-dashboard n Annotation: @EnableHystrixDashboard o Client: n Dependency: spring-cloud-starter-hystrix spring-boot-starter-actuator n Configuration: @HystrixCommand(fallbackMethod = "fallback")
  • 31.
    o All thisis a long process of discovery. o Capture all this in your Maven starter with auto-configuration o It is not needed to reinvent the wheel.
  • 32.
    o There aredifferent log aggregation and analysis alternatives: n EKK=Elastic+Kinesis+Kibana (AWS) n Graylog - nice alerts Alternatives
  • 33.
    Kubernetes/Kubeflix o Language andtechnology agnostic o Reduces the need for: n discovery service n client-side loadbalancing n edge-service proxy
  • 34.
  • 35.
    Resources o https://github.com/dndanoff/microservices o 12Factor Application o Spring Cloud Project o Spring Cloud Docs