developer experience with spring cloud - jax london · developer experience with spring cloud...
Post on 11-Nov-2018
229 Views
Preview:
TRANSCRIPT
Developer Experience withSpring Cloud
Spencer Gibb, Dave Syer, 2015
AuthorsSpencer Gibb,@spencerbgibb,sgibb@pivotal.io
Dave Syer,@david_syer,dsyer@pivotal.io
Developer ExperienceMicroservices lead to a very open flexible architecture
Developer needs to work on isolated codebase
Noone wants to redeploy the universe for every commit
What tools and techniques are available to help?
Database/middleware: Dockerstandard docker images exist for all common middleware
perfect for development
can be used in production with care
Middleware: Discovery and DIHow to wire up your application code to required middleware, and make the same code run in all environments?
be Cloud Native
use autoconfiguration
use Service Discovery and Registry patterns
use Spring Cloud Connectors (a bit: see blog)
use Spring Cloud Stream for messaging
Provisioning a system for testingDocker compose (great for repeatability)
Locally with VirtualBox
Remotely: Lattice AWS, Cloud Foundry, Kubernetes, Terraform, etc.
CI systems native support (travis, bamboo, etc.)
Debugging and fault findingYour app won’t always work first time. How to diagnose the problem?
dynamic log levels at runtime
actuator endpoints: /env, /trace, /mappings, /autoconfig
feature switches
remote debugger (see later: Spring Boot Devtools)
deploy locally
distributed tracing (http and messages)
https://ngrok.com (http proxy with replay)
Service discovery background
Routing from remote system to IDE
Tunnel
Local Service Remote Client
Service Registry
Cloud Foundry
local dev experience
use proxy to tunnel back to IDE (e.g. ngrok)
Spring Tool Suite and Boot Dashboard
Loadbalancer configuration modelsflag to enable local route
prefer route that “looks local”
flag a request (e.g. header with correlation ID)
Customizing RibbonRibbon is a clientside smart loadbalancer from Netflix OSS
IRule: Loadbalancing algorithm (roundrobin, random, etc…)ServerList: Where to get the list of servers to loadbalance.
ServerListFilter: filters list of servers.
@RibbonClient: allows configuration for a named ribbon client.
StubbingHigh level:
Greenfield (dependent services don’t exist yet, write stubs)
Brownfield (dependent services exist and have published artifacts)
Example tools/approaches:
publish producer stubs vs. consumer tests
"forced stubbing": microinfra from 4finance
adhoc stubbing: accurest, wiremock, stubby4j, Spring MVC
embedded stubs vs. remote stubs
Stubbing Brownfield ServicesCreate Wiremock stubs using tests or dsl
AccuREST uses a groovy dsl to create integration tests and stubs.
Spring REST Docs uses tests to generate snippets for documentation and can be used to create stubs.
Run Wiremock using generated stubs
Run consuming services against Wiremock stubs
Stubbing: AccuREST DSLGenerates a MockMVC test and a Wiremock stub
import io.codearte.accurest.dsl.GroovyDsl
GroovyDsl groovyDsl = GroovyDsl.make { request { method 'GET' url '/foo' } response { status 200 headers { header 'Content-Type' : 'application/json;charset=UTF-8' } body '''{ "value" : 42 }''' }}
Stubbing: Spring REST Docs
@Beforepublic void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context) .apply(documentationConfiguration() .snippets().withDefaults(curlRequest(), httpRequest(), httpResponse(), new WiremockStubSnippet())) .build();}
@Testpublic void foo() { this.mockMvc.perform(get("/foo") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(document("foo"));}
Stubbing: Wiremock Stub
{ "request": { "method": "GET", "url": "/foo" }, "response": { "status": 200, "headers": { "Content-Type": "application/json;charset=UTF-8" }, "body": "{\"value\":42}" }}
Stubbing: 4finance stubrunnerPublish stub files to nexus repository (or local maven repo)
Describe all services dependencies in application.ymlStubrunner uses list of dependencies
Grabs stubs from repository
Runs a wiremock server for each dependency using fetched stubs
Registers server in service discovery
Consuming service can function against stubs
Greenfield Stubbing: Spring MVC
@Controllerpublic class StubFleetLocationServiceApplication {
@RequestMapping("/locations") public String home() { return "forward:/stubs/locations.json"; }
...
}
Nice side effect: mock MVC and restdocs for tests and docs can be reused to verify real service contract
Hot reloading and code swappingBasic IDE features (JVM hotswap and resource reload)
Spring Boot devtools app restart and browser plugin
STS
Spring Loaded (Grails, JHipster)
JRebel
Devtools locallyApp monitors its classpath and restarts when changes detected:
IDE
AppFiles
update
monitor
Browser
Devtools with browserBrowser plugin automatically refreshes views:
RemoteClient AppIDE
AppFiles
monitorupdate
monitor
Browser
Hot reloading and debuggingHot reloading of “local” application code deployed on Cloud Foundry / Lattice
RemoteClient AppIDE
AppFiles
monitorupdate
Cloud Foundry
Spring Boot support via devtools
classloader flushes dirty resources
remote debug also possible (but slow)
Linkshttp://presos.dsyer.com/decks/springclouddevexperience.html
http://cloud.spring.io
http://spring.io/blog
https://github.com/springcloud
https://github.com/springcloudsamples
https://github.com/springone2gx2015
https://github.com/spencergibb/springclouddependenciessample
← →23 / 23Go to Slide: Go
top related