• Stars
    star
    353
  • Rank 120,322 (Top 3 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated 5 months ago

Reviews

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

Repository Details

Brewing beer with Spring Cloud has never been that easy...

Build Status

Brewery

Ever wanted to brew your beer using microservices? This repository will allow you to do so!

This repository is used throughout the Spring Cloud libraries builds as end to end testing set up. Check Acceptance Tests Readme for more information.

How does the brewery work?

Since pictures say more than words...

Here is the business flow of the app. Below you'll see more detailed explanation with numbers corresponding to the numbers in the diagram

Diagram

And here additional tech related applications:

Diagram

And here how the flow of apps look like (screenshot taken from Zipkin)

Diagram

Presenting service (point of entry to the system)

Here is the UI

UI

  • Go to the presenting service (http://localhost:9991 or to https://brewery-presenting.${PCF_DOMAIN}) and order ingredients. PCF_DOMAIN is the domain set to your CF installation. If you deploy to Pivotal Web Services it will default to cfapps.io (so the link for PWS will be https://brewery-presenting.cfapps.io) (1)
  • A request from the presenting service is sent to the aggregating service when order is placed (2)
  • A "PROCESS-ID" header is set and will be passed through each part of beer brewing

Brewing service

Brewing service contains the following functionalities:

Aggregating

  • Service contains a warehouse ("database") where is stores the ingredients
  • Spring Cloud Gateway will be used as proxy (3)
  • Once the ingredients have been received an event is emitted (7)
  • You have to have all 4 ingredients reach their threshold (1000) to start maturing the beer
  • Once the brewing has been started an event is emitted (7)
  • Once the threshold is met the application sends a request to the maturing service (8)
  • Each time a request is sent to the aggregating service it returns as a response its warehouse state

Maturing

  • It receives a request with ingredients needed to brew a beer
  • The brewing process starts thanks to the Thread.sleep method
  • Once it's done an event is emitted (9)
  • And a request to the bottling service is sent with number of worts (10)
  • Presenting service is called to update the current status of the beer brewing process

Bottling

  • Waits some time to bottle the beer
  • Once it's done an event is emitted (11)
  • Presenting service is called to update the current status of the beer brewing process (12)

Ingredients Service

  • Returns a fixed value of ingredients (5)

Reporting Service

  • Listens to events and stores them in the "database"

Proxy (Spring Cloud Gateway)

  • Proxy over the "adapters" to external world to fetch ingredients
  • Routes all requests to the respective "ingredient adapter" (4)
  • For simplicity we have one ingredient adapter called "ingredients" that returns a stubbed quantity
  • Returns back the ingredients to the aggregating (6)

Project structure

โ”œโ”€โ”€ acceptance-tests (code containing acceptace-tests of brewery)
โ”œโ”€โ”€ brewing          (service that creates beer - consists of aggregating, maturing, bottling functionalities)
โ”œโ”€โ”€ common           (common code for the services)
โ”œโ”€โ”€ docker           (docker scripts for additional apps - e.g. graphite)
โ”œโ”€โ”€ config-server    (set up for the config server)
โ”œโ”€โ”€ eureka           (Eureka server needed for Eureka tests)
โ”œโ”€โ”€ img              (the fabulous diagram of the brewery)
โ”œโ”€โ”€ ingredients      (service returns ingredients)
โ”œโ”€โ”€ presenting       (UI of the brewery)
โ”œโ”€โ”€ reporting        (service that listens to events)
โ””โ”€โ”€ proxy            (Spring Cloud Gateway that forwards requests to ingredients)

How to build it?

./mvnw clean install

How to build one module?

E.g. brewing module

./mvnw clean install -pl brewing

How to run it?

Prerequisite

YOU NEED DOCKER-COMPOSE INSTALLED TO RUN THE BREWERY ON YOUR LOCAL MACHINE!

Running Brewery

The easiest way is to:

  • GO to the cloned brewery where you have the runAcceptanceTests.sh script
  • For all options just run runAcceptanceTests.sh without any options or with --help switch

Once you run the script, the brewery app will be cloned, built with proper lib versions and proper tests will be executed.

You can run this script to have the setup done for you in no time (example for SLEUTH tests execution):

git clone https://github.com/spring-cloud-samples/brewery.git
cd brewery
bash runAcceptanceTests.sh -t SLEUTH

Examples

I want to just run all the apps and have fun

Execute:

bash runAcceptanceTests.sh -x

I want to just run all the apps with Eureka and have fun

Execute:

bash runAcceptanceTests.sh -x -t EUREKA

I want to run end to end tests of Consul and kill all the apps after the tests finish

Execute:

bash runAcceptanceTests.sh -t CONSUL -ke

I want to run end to end tests of Consul on my docker-machine (ip. 1.2.3.4) and kill all the apps after the tests finish

Execute:

bash runAcceptanceTests.sh -t CONSUL -ke -h 1.2.3.4

I want to run end to end tests of Consul, kill all the apps after the tests finish and skip build

Execute:

bash runAcceptanceTests.sh -t CONSUL -ke -s

I just want to kill all the brewery related apps

Execute:

bash runAcceptanceTests.sh -n

How to run a single module?

To run a single module just execute (e.g. presenting module):

./mvnw spring-boot:run -Dspring.profiles.active=dev -pl presenting

Authors

The code is ported from https://github.com/uservices-hackathon

The authors of the initial version of the code are:

  • Marcin Grzejszczak (marcingrzejszczak)
  • Tomasz Szymanski (szimano)

More Repositories

1

eureka

Java
500
star
2

customers-stores

Two microservices for customers and stores
Java
431
star
3

spring-cloud-contract-samples

Samples for Spring Cloud Contract project
Java
379
star
4

configserver

Java
371
star
5

spring-cloud-gateway-sample

Sample Spring Cloud Gateway Application
Java
360
star
6

feign-eureka

Example of using feign with eureka
Java
236
star
7

config-repo

Configuration files for the server sample
138
star
8

bookstore-service-broker

Sample application for Spring Cloud Open Service Broker
Java
72
star
9

spring-cloud-circuitbreaker-demo

Samples demonstrating how to using Spring Cloud Circuitbreaker
Java
64
star
10

spring-cloud-sleuth-samples

Contains isolated samples of Spring Cloud Sleuth
Java
23
star
11

spring-cloud-contract-nodejs

Spring Cloud Contract with Node JS application
Shell
22
star
12

spring-cloud-config-vault

Sample application demonstrating how to use Hashicorp Vault as a backend for a Spring Cloud Config server
Java
16
star
13

svn-config-server

Sample Config Server and Config Client. The Config Server is configured to use Subversion rather than git
Java
16
star
14

spring-cloud-app-broker-samples

Sample apps for https://github.com/spring-cloud/spring-cloud-app-broker
Java
8
star
15

spring-cloud-square-retrofit-web

Demo project for Spring Cloud Square Retrofit Web
Java
3
star
16

sleuth-issues

Samples for Sleuth that replicate issues
Java
2
star
17

spring-cloud-function-samples

1
star
18

spring-cloud-square-retrofit-webclient

Java
1
star
19

spring-cloud-intro-demo-config

Centralised Configuration for Spring Cloud Intro Demo
1
star
20

spring-cloud-contract-nodejs-external-contracts

External contracts for the Spring Cloud Contract NodeJS sample
Java
1
star