• Stars
    star
    191
  • Rank 202,877 (Top 4 %)
  • Language
    Java
  • Created over 10 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sample for Spring Boot based REST microservices

REST based micro-services sample

Build Status

tl;dr

  • Two Spring Boot based Maven projects that are standalone applications:
    • Stores (MongoDB, exposing a few Starbucks shops across north america, geo-spatial functionality)
    • Customers (JPA)
  • The customers application tries to discover a search-by-location-resource and periodically verifying it's still available (see StoreIntegration).
  • If the remote system is found the customers app includes a link to let clients follow to the remote system and thus find stores near the customer.

Fundamentals

The core domain and focus of the example can be explored by simply starting both the customer and the store service using mvn spring-boot:run. The store service exposes a resource to trigger geo-spatial queries for Starbucks shops given a reference location and distance.

The customer service

The customer service has a static reference to the store service configured (http://localhost:8081, as bean in CustomerApplication.staticServiceInstanceProvider()) and traverses a set of hypermedia links to discover the resource solely by knowing the relation names. The service then adds a link to the discovered system, expanding the link with the current location of the customer (in CustomerResourceProcessor.process(…)). This result of that can be seen by follwing the customers relation in the root resource of the customer service. A stores-nearby link shows up.

As the store system might become unavailable, we verify the presence of it by issuing a HEAD requests to the discovered resource (time interval configured by the cloud.hypermedia.refresh.fixed-delay property in application.properties). This is implemented by the DiscoveredResourceRefresher auto-configured by CloudHypermediaAutoConfiguration, a tiny Spring Boot extension.

The use of Hystrix

The customer service uses Hystrix to short-circuit the discovery calls trying to find the store system if the link discovery or validation fails repeatedly. To see this working run the hystrix-dashboard app (mvn spring-boot:run), browse to http://localhost:7979/hystrix and point the dashboard to the customer service's Hystrix stream (http://localhost:8080/hystrix.stream).

While the store service is running, you should see the requests being forwarded, the circuit closed. Stop the store service and see how the failing requests will trigger the circuit to be opened at some point (a couple of seconds usually). Restart the store service and see how after a couple of seconds the circuit gets closed again, the resource discovery is re-triggered and the stores-nearby link appears in the resources the customer service exposes.

Using service discovery

As an alternative to the static service reference the customer service uses by default, service discovery via Eureka can be used. Make sure both the customer and store service are stopped. Start the eureka-server application using mvn spring-boot:run. Browse http://localhost:8761 to see the Eureka web interface.

Now start both the customer and the store service with the cloud profile enabled (mvn spring-boot:run -Dspring.profiles.active="cloud"). Inspecting the Eureka web interface you should see both instances being registered with the registry. The customer service now uses a DiscoveryClient to obtain a ServiceInstance by name (see the CustomerApplication.CloudConfig.dynamicServiceProvider(…) bean definition).

More Repositories

1

spring-restbucks

Implementation of the sample from REST in Practice based on Spring projects
Java
1,231
star
2

sos

Sample projects for my talk "Refactoring to a System of Systems"
Java
242
star
3

repositories-deepdive

Sample code for the Spring Data JPA repositories deep dive talk
Java
166
star
4

spring-domain-events

This has been moved to Moduliths –https://github.com/odrotbohm/moduliths.
Java
100
star
5

spring-playground

A collection of tiny helpers for building Spring applications
Java
97
star
6

arch-evident-spring

Java
85
star
7

whoops-architecture

Sample code for my talk "Whoops! Where did my architecture go?"
Java
76
star
8

lectures

Lecture scripts and slides I use during the Software Engineering course at TU Dresden
Java
68
star
9

spring-modulith-deep-dive

Sample code for the Spring Modulith Deep Dive workshop / training
Java
52
star
10

ninjector

Ninjector - the cure for Field Injection Anxiety
Java
42
star
11

spring-events-deep-dive

Sample code for my talk "A Deep Dive into Spring Application Events".
Java
40
star
12

spring-rest

Sample project for Spring 3 REST style web application
Java
30
star
13

tactical-ddd-workshop

Sample code for my Tactical DDD with Java workshop
Java
26
star
14

spring-hateoas-sample

Sample project to show Spring HATEOAS in action
Java
24
star
15

spring-five-functional-reactive

Java
20
star
16

spring-restbucks-training

Spring RESTBucks - Training
Java
17
star
17

mawspring

Modulithic Applications with Spring
Java
15
star
18

jddd-legacy

Java
10
star
19

spring-record-support

Spring extension to make JDK 14's records work OOTB with Spring libraries
Java
7
star
20

hades-showcase

Sample project to show how Hades eases JPA repository implementation.
Java
7
star
21

shop-modulith

Sample code for the presentation at betterCode() Spring
Java
7
star
22

spring-examples

Canonical samples to showcase features of dedicated Spring versions
Java
6
star
23

spring4-guided-tour

Sample code for new features in Spring 4
Java
5
star
24

maws

Sample code for Modulithic Applications with Spring
Java
5
star
25

klient

A hypermedia client API written in Kotlin
Kotlin
5
star
26

spring-jmx-namespace

JMX utility Spring namespace
Java
3
star
27

Spring-Webflow-Tag-Library

Spring Webflow tag library
Java
2
star
28

spring-tx-events

Spring transaction bound application events
Java
2
star
29

odrotbohm.github.com

Website (Production)
HTML
2
star
30

spring-boot-devtools-sample

Java
2
star
31

spring-samples

Various sample scenarios to illustrate Spring goodness
Java
2
star
32

hibernate-criteria-statistics

Sample projects on how to enable Criteria statistics in Hibernate with AspectJ until HHH-3452 gets fixed
Java
1
star
33

hibernate-bugs

Java
1
star
34

asciidoctor-pdf-example

1
star
35

spring-data-release-cli

Simple shell to execute Spring Data releases
Java
1
star
36

reactive-4te

Java
1
star
37

spring-modulith-accelerator

Java
1
star
38

pv-charger

Java
1
star
39

asciidoctor-pdf-sample

Shell
1
star
40

datanucleus-test

Java
1
star
41

scs-workshop

Self-contained systems workshop
1
star