spring boot and actuators – live blogging from spring days

Spring Boot and Actuators
Speaker: John Humphreys
See list of all blog posts from conference

Spring Boot

  • makes it easy to create standalone apps
  • opinionated view of which third party libraries to use
  • 9 lines of code to get coding
  • can embed Tomcat or Undertwo in your app
  • No Spring config needed as defaults
  • Makes uberwar
  • Add 1 lines to run war as init.d service
  • many integrations
  • only need two maven dterations

9 lines of code
the 9 lines of code to get started are an annotation and a one ine main method
SpringApplcation run (MyApp.class,args);
The other lines are imports/class name/braces/etc

Annotation
@SpringBootApplicatoin replaces need for many other common spring annotations

  • @Configuraton – define beans in Java
  • EnableAutoConfiguration – configure beans
  • @ComponentScan – search for and wire up classes

Add an endpoint to actually do something. map URLs and functionality

Spring Boot Inititialzr – enter dependencies you want online and it gives you a working spring boot web service without needing dependencies

Maven

  • spring-boot-starter-pom parent pom so can get started.
  • spring-boot-starter-web dependency for deploying to Tomcat
  • spring-boot-starter-actuator – for monitoring the application
  • spring-boot-starter-hateos- for adding monitoring as REST endpoint and in browser
  • spring-boot-maven-plugin – creates uber war. has option to embed init.d support by setting &ltexecutable>true</executable>
  • spring-boot-admin-server-ui – minotrs and lets interact with app – just flag with @EnableAdminServer, can expose with JMX

application.properties – lets override defaults

actuator

  • for monitoring
  • provides a lot of URLs by default and can add more of your own
  • Each cluster has own actuator
  • Masks passwords by default
  • Very customizable
  • Can show live thread dumps
  • Text based – use UI dependency to see graphically

Overall – cool to see it built live – pieces are easy to understand. I didn’tknow what n actuator was so learned that too. I’ve only een the very basics of Spring Boot so this was a great first talk for me to hear. An embedded Tomcat is interesting. Easy because one thing. Tomcat has frequent patches though so definitely would want continuous deployment!

Live Blogging from Spring Days New York

Tuesday

Wednesday

Overall comments:
I learned a lot so definitely worth attending! I would have liked a speaker “test your hardware opportunity” in the morning. Most of the speakers needed help to get settled.

reactive programming for java developers – rossen stoyanchev – qcon

For more QCon posts, see my live blog table of contents.

General notes

  • Spring 5 has reactive features.
  • Maybe a third of the audience is doing something with reactive, a little more have read about it (that’s me) and a lot haven’t heard of it. Which is good given the title of this talk!
  • Moore’s law slowing down. No more free lunch from the hardware
  • Now apps more distributed/independent/cloudbased compared to 10 years ago
  • Now we expect latency
  • Thread now has to do more async things. Hit limits of scale. imperative logic more complicated.

Other approach

  • Async/non-blocking
  • Use very few threads. node.js has a single thread. Must be careful because blocking those few threads blocks the whole app
  • Reactive programming – think async. Not everything is a callback

Comparing styles

  • Imperative
    • call a method, get a result, do something with that result
  • Async
    • return a Future instead of a value. Don’t throw a checked exception because my happen in a different thread. They are asynchronous in that you can get a result later. But when you eventually call feature.get(), it throws different checked exceptions.
    • In Java 8, can return a CompletableFuture and call future.whenComplete((user, throwable) -> {})
    • If doing a findAll(), the future/completable future approach doesn’t give you a callback/return anything until all of them are ready. You can’t stream or could run out of memory.
    • Async results as stream – get one notification per data item and another for completion or error
  • Declarative
    • Focus on what, not how
    • Declare what should happen rather than focusing on callbacks
    • Java 8 stream API uses this style. It is meant for collections and pull based/usable once
    • Hot streams – latency sensitive streams, data need to be pushed for you
    • Cold streams – pull based

Reactive libraries

  • Stream like API
  • Can be used for hot/cold streams
  • Project Reactor – Similar to ReactiveX, easy to bridge to Java 8 streams. (ReactiveX is like XUnit – commonality for different languages)

Abstractions

  • Flux – sequence of 0 to n – equivalent of Java 8 stream – can convert to/from Java 8
  • Mono – sequence of 0 or 1 – can convert to/from CompletableFuture

Reactive streams spec

  • Back pressure – producers must not overwhelm consumers. Communicates if downstream isn’t ready for more items. Ex: a slow client like a mobile device isnt able to handle more data and server isn’t blocking
  • Small API – only 4 interfaces
  • Rules
  • Interoperability across reactive components so can compose chain

Java 9

  • Reactive streams included (the four interfaces)
    • Publisher
    • Subscriber
    • Subscription
    • Processor
  • Use a reactive library. Don’t implement the four interfaces yourself
  • subscribe() triggers the flow of data
  • “push” was missing until now. Want in JDK to have foundation
  • Classes
    • java.util.concurrent.Flow – the four interfaces
    • SubmissionPublisher – bridge to reactie streams
    • Tie-ins to CompletableFuture and Stream

Reactor

  • GA release scheduled for July
  • Currently called 2.5. Might changed to 3.0

Reactive Spring MVC

  • Apps annotate controllers even now.
  • Return a Flux type.
  • Spring MVC itself needs to change a lot – called Spring Web Reactive
  • The servlet API assumes blocking. There are async workarounds. Servlet 4.0 might support reactive spring integration, but probably just the basics. Using own bridge to Servlet 3.1 in meantime.
  • Can still use Jetty/Tomcat. They are non-blocking behind the scenes.
  • Don’t need servlet container. Can use Netty.
  • HandlerMapping – change to return a Mono so can be non-blocking
  • Focusing on REST/microservices scenarios

Other reactive efforts

  • MongoDB – reactive driver
  • Couchbase – reactive driver
  • Thymeleaf – split templates into chunks and throttle to respect backpressure