This is companion code to a medium article of the same name. The article is a step-by-step guide with each major step corresponding to a branch in this repo.
WHOPPR is a fictional pizza ordering sytem composed of various services all smushed up in one monolothical application. The following Spring Cloud services are then used to break it down into micro-services.
- Spring Cloud Netflix (Zuul and Eureka)
- Spring Cloud Feign
- Spring Cloud Contracts and
- Spring Cloud Security
- jdk 8
- gradle 6+
- Mongo DB community edition
- A good IDE
- After installing pre-requisites, do below to verify proper setup:
$ git clone https://github.com/mpdroid/whoppr.git
$ cd whoppr
$ ./gradlew clean build
- To view the application code in its monolithic state:
$ git checkout 1-strawman
- Verify with:
$ ./gradlew clean build
$ ./gradlew monolith:bootRun # In another terminal window
$ ./gradlew monolith:cucumber -PenableCucumber
-
Create master
build.gradlewith common tasks and imports -
Move data model, configuration and exception classes to
commonlibrary sub-project -
Move test helpers to
test-utilslibrary sub-project -
Move acceptance tests from
monolithintoacceptancesub-project -
To view the foundational elements added to the workspace before refactoring:
$ git checkout 2-foundations
- Verify with:
$ ./gradlew clean build
$ ./gradlew monolith:bootRun # In another terminal window
$ ./gradlew acceptance:cucumber -PenableCucumber
-
Update master build.gradle with
Spring Cloudimports. -
Enable Spring Cloud Contract in all sub-projects through master
build.gradle. -
Add gateway capabilities to
monolithwithNetflix Zuul. -
Create service
registrysub-project usingEureka Server. -
Add
Eureka ClientandOpenFeigntomonolithand stir well. -
To view the infrastructure elements added to the workspace:
$ git checkout 3-eureka
- Verify with:
$ ./gradlew clean build
$ ./gradlew registry:bootRun # separate terminal
$ ./gradlew monolith:bootRun # separate terminal
$ ./gradlew acceptance:cucumber -PenableCucumber
- Connect to http://localhost:8761 with configured credentials to verify that
whopprservice (name of our monolith) is visible in the registry.
- Move menu service out of
monolith - Write contract tests
- Publish contract stubs to local maven repo
- Create feign client in
monolith - Rewrite consumers to consume feign client
- Rewrite consumer integration tests to use contract stubs
- Update Zuul routes
- Verify with:
$ ./gradlew clean build
$ ./gradlew registry:bootRun # separate terminal
$ ./gradlew menu:bootRun # separate terminal
$ ./gradlew monolith:bootRun # separate terminal
$ ./gradlew acceptance:cucumber -PenableCucumber
- Connect to http://localhost:8761 with configured credentials to verify that
whopprandmenuservices are visible in the registry.