• Stars
    star
    652
  • Rank 69,062 (Top 2 %)
  • Language
    Java
  • Created about 9 years ago
  • Updated about 6 years ago

Reviews

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

Repository Details

A Java Microservice & CQRS Demo using Spring Boot, Axon & Docker

#Microservices with Docker, Spring Boot, Spring Cloud and Axon

This is a non-trivial demonstration of how to build a CQRS microservice application consisting of several collaborating microservices. It combines together all of the following elements in order to produce one logical application - a simple Product Master Data service.

#About the Author

Ben Wilcock works for Pivotal as a Cloud Solutions Architect. Ben has a passion for microservices, cloud and mobile applications and helps Pivotal's Cloud Foundry customers to become more responsive, innovate faster and gain greater returns from their software investments. Ben is also a respected technology blogger who's articles have featured in DZone, Java Code Geeks, InfoQ and more.

##Running the Demo

Running the demo is easy. The whole environment has been packaged to be run as a series of Docker containers. To run the code, you'll need to have the following software installed on your machine. For reference I'm using Ubuntu 16.04 as my OS, but I have also tested the app on the new Docker for Windows Beta successfully.

  • Java SDK 8
  • Docker (I'm using v1.8.2)
  • Docker-compose (I'm using v1.7.1)

If you have these, you can run the demo by following the process outlined below.

If you have either MongoDB or RabbitMQ running locally already, please shut down these services before continuing in order to avoid port clashes.

###Step 1: Build the containers

In a new empty folder, at the terminal execute the following command to download the latest code for this demo.

$ git clone https://github.com/benwilcock/microservice-sampler.git

Then build the docker container images.

$ cd microservice-sampler
$ ./gradlew clean image

This will create a series of Docker container images, one for each of the spring-boot microservices used in this demo.

###Step 2: Start the Microservices

There are seven Docker container images in this microservice group, they are 'mongodb', 'rabbitmq', 'config', 'discovery', `gateway-service', 'product-cmd-side', and 'product-qry-side'. The logical architecture looks like this:-

Architecture

Because we're using docker-compose, starting the microservices is now simply a case of executing the following command.

$ docker-compose -f wip.yml up

If you want to see which docker instances are running on your machine at any time, open a separate terminal and execute the following command:-

$ docker ps

###Step 3: Integration Test (Manual)

So far so good. Now we want to test the addition of products. In a new terminal window (ctrl-alt-t in Ubuntu), execute the following curl request...

$ curl -X POST -v --header "Content-Type: application/json" --header "Accept: */*" "http://localhost:8080/commands/products/add/1?name=Everything%20Is%20Awesome"

If you're using the public beta of Docker for Mac or Windows (which is highly recommended), you may need to swap 'localhost' for the IP address shown when you ran 'docker ps' to observe the running servers.

You should see the following response.

*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /commands/products/add/1?name=Everything%20Is%20Awesome HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.47.0
> Content-Type: application/json
> Accept: */*
>
< HTTP/1.1 201 Created
< Date: Wed, 29 Jun 2016 14:14:26 GMT
< X-Application-Context: gateway-service:production:8080
< Date: Wed, 29 Jun 2016 14:14:26 GMT
< Transfer-Encoding: chunked
< Server: Jetty(9.2.16.v20160414)

The response code should be HTTP/1.1 201 Created. This means that the MP3 product "Everything is Awesome" has been added to the command-side event-sourced repository successfully.

Now lets check that we can view the product that we just added. To do this we use the query-side API and issue a simple 'GET' request.

$ curl http://localhost:8080/queries/products/1

You should see the following output. This shows that the query-side microservice has a record for our newly added MP3 product. The product is listed as non-saleable (saleable = false).

{
  "name" : "Everything Is Awesome",
  "saleable" : false,
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/queries/products/1"
    },
    "product" : {
      "href" : "http://localhost:8080/queries/products/1"
    }
  }
}

That's it! Go ahead and repeat the test to add some more products if you like, just be careful not to reuse the same product ID when you POST or you'll get a 409 Conflict error.

If you're familiar with MongoDB you can inspect the database to see all the events that you've created. Similarly if you know your way around the RabbitMQ Management Console you can see the messages as they flow between the command-side and query-side microservices. If you like you can also execute the integration tests using the command..

$ ./gradlew integration-test:integrationTest

More Repositories

1

spring-cloud-gateway-demo

Code and articles to help folks get started with Spring Cloud Gateway.
Java
181
star
2

spring-rsocket-demo

Getting Started With RSocket in Spring Boot
Java
147
star
3

android-alltest-gradle-sample

A template Gradle / Android project which integrates and configures Robolectric, Robotium, JUnit4 and standard Android Instrumentation together in one project.
Java
128
star
4

spring-cloud-stream-demo

Simple Event Driven Microservices with Spring Cloud Stream
Java
98
star
5

pcf-axon-cqrs-demo

Demonstrates CQRS and Event Sourcing microservices in Java using Pivotal CloudFoundry, SpringBoot and the Axon Framework.
Java
52
star
6

axon-initializr

A customised Spring Initailizr to help folks create Axon based CQRS & Event Sourced applications from scratch.
Java
52
star
7

backstage-plugin-backchat

A quick and dirty frontend plugin that integrates a GenAI feature into Backstage
TypeScript
47
star
8

springone-2020-rsocket-talk

Getting started with RSocket
Java
31
star
9

pcf-spring-cloud-services-demo

Demonstrates how to write Spring Boot applications that use the PCF Spring Cloud Services (Hystrix, Eureka and Config)
Java
25
star
10

android-couchbase-dagger-robolectric

This Android / Gradle project integrates Couchbase, Robolectric and Dagger so that unit testing can occur without the need for a connected device or emulator.
Java
17
star
11

spring-cloud-dataflow-demo

Demonstration of streaming applications using Spring Cloud Data Flow with microservices written in Spring Cloud Stream.
Java
12
star
12

spring-cloud-contracts

Demonstrates the use of Spring Cloud Contracts for Consumer Driven API's
Java
12
star
13

cf-cqrs-microservice-sampler

CQRS Microservice Demo that runs and scales on CloudFoundry.
Java
9
star
14

backstagecon-2023

BackstageCon 2023
6
star
15

axon-cqrs-sample

Java
6
star
16

test-driven-jee-modernisation

An example of how ArchUnit can be used to help you eradicate dependencies to the Java Enterprise framework.
Java
3
star
17

python-cloudfoundry-demo

Python
2
star
18

pcf-route-service

Demonstrates a simple PCF Route Service that injects a new HTTP header "x-auth-user" containing a signed JWT token.
Java
2
star
19

tanzu-application-platform-scripts

Shell
2
star
20

spring-cloud-connectors-demo

Demonstrates connecting to services hosted in Cloud Foundry from Spring Boot using spring-cloud-connectors.
Java
2
star
21

tap-demo-config-files

tap demo configuration files
2
star
22

test-java-002

Java
1
star
23

microservice-sampler-config

configuration used by the config server for the microservice-sampler microservices.
1
star
24

python-pipenv

Simple Python App using PipEnv package management
HTML
1
star
25

spring-oauth-sso-demo

Demonstrates the use of OAUTH2 with SpringBoot.
Shell
1
star
26

backstage-catalogs

backstage-catalogs
1
star
27

axon-jpa-example

A simple demo of Queries backed by JPA based "projections" using Axon 4.0
Java
1
star
28

springboot-djl-demo

Demonstrates ML based sentiment analysis via REST API.
Java
1
star
29

akka-cqrs-sample

Java
1
star
30

systems-techdocs

The repo contains some sample Backstage TechDocs documentation for the Where For Dinner sample application.
Shell
1
star
31

TripComputer-Android-Project

TripComputer is an Android App that displays time, distance, cost and many more facts about your journey.
Java
1
star