Spring & Spring Boot stuff
Woofer was originally designed to be a showcase web app to demonstrate and enforce logging best practices.
But actually it is also a quite advanced Spring Boot-based microservices project sample that could be used as a bootstrap to create a microservices application.
This page highlights Spring & Spring Boot modules used in Woofer.
Woofer's microservices
Woofer heavily relies on Spring Boot, and Spring Cloud to implement a microservices architecture.
It involves the following components:
service-registry
: the service registry server, basically implemented by Eureka Server.router
: a router and load balancer service, basically implemented by Zuul; only required if you want to load balance thewoofer-webfront
service.woofer-webfront
: this is the web front-end application, that the end-user will use to connect, read and post woofs.woofer-backend
: this is the backend service, a pure JSON/Rest API service, that is consumed by thewoofer-webfront
and possibly mobile apps (not part of the demo).woofer-notifier
: this is a notification service, that is asynchronously triggered when domain events occur (a user posts a woof, or subscribes/unsubscribes to a mate). It is called asynchronously bywoofer-backend
.- database: a basic MariaDB instance
- logs centralization system: an ELK instance
- distributed tracing system: a basic Zipkin server.
Woofer's profiles
By default, when launching Woofer services locally with no profile, it will use a memory database (h2), output Java and Http logs to the console.
But Woofer has several Spring Boot profiles to adapt to several environments.
Profile | Description | Required environment variables |
---|---|---|
logstash | used to ship Java and Http logs to a Logstash server in JSON native format | $LOGSTASH_HOST , $LOGSTASH_PORT and optionally $MD_PROJECT (project ID metadata) |
h2 | uses h2 as database (mem or file) | $H2_DATASOURCE_URL (default in memory), $H2_USER (default sa ) and $H2_PASSWORD (default none) |
mysql | uses MySQL or MariaDB as database | $MYSQL_DATASOURCE_URL (default on localhost ), $MYSQL_USER (default root ) and $MYSQL_PASSWORD (default none) |
zipkin | activates distributed tracing with a Zipkin server | $ZIPKIN_URL and $ZIPKIN_SAMPLING (a ratio) |
openshift | adapts the Woofer configuration to an OpenShift v3 environment (work in progress) | none |
jmx | exposes Spring Boot Actuator metrics through JMX | none |
Spring Data JPA
Spring Data JPA is used to implement our Object-Relational Mapping (ORM).
It allows creating Data Access Objects (called Respositories
in Spring terminology) simply by annotations and interfaces.
See:
Spring Data Rest
Spring Data Rest is used to build hypermedia-driven REST web services on top of Spring Data repositories.
Woofer also uses the Projections feature.
See:
Spring Cloud Netflix
Spring Cloud Netflix is a great contribution from Netflix, that embeds several features to build cloud applications.
Eureka
Eureka server & client provides a very cheap and robust way of implementing services registration and discovery in a microservices architecture (more info).
Its use is quite straightforward as it only requires adding the right dependency to your pom.xml
, and a basic
annotation to your Sprint Boot application (either @EnableEurekaClient
or @EnableEurekaServer
).
Feign
Feign allows implementing declarative REST clients (i.e. through interfaces & annotations).
It is used in woofer-webfront
to implement the woofer-backend
REST client.
See:
Ribbon
Ribbon provides client side load balancer.
Its use is quite straightforward as it only requires adding the right dependency to your pom.xml
.
Spring Boot Actuator
Spring Boot Actuator provides a set of tools to monitor and manage your application.
Apart from default management endpoints, woofer-webfront
and woofer-backend
publish some business metrics to count active
sessions, woofs and subscriptions.
See:
Spring REST Docs
Spring REST Docs is a tool for generating part of REST API documentation.
It is used in woofer-backend
project to generate the reference API documentation.
See:
Spring Cloud Sleuth
Spring Cloud Sleuth is used for distributed tracing & logs correlation (see Logging - Code page for more details).