Giter VIP home page Giter VIP logo

cqrs-microservice-sampler's Introduction

#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

cqrs-microservice-sampler's People

Contributors

benwilcock avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cqrs-microservice-sampler's Issues

Updating to Axon 3.1.1

can you please suggest a way to upgrade this to new version of Axon 3.1.1
because interfaces like EventBusTerminal are not there in 3.1.1.

jdk version in Dockerfile should be updated

FROM openjdk:8
VOLUME /tmp
EXPOSE 9000 9001
ADD product-command-side.jar app.jar
RUN sh -c 'touch /app.jar'
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

upgrade to newer spring boot and gradle versions

Right now the project is using old versions of spring boot and is therefore also not compatible with newer gradle versions (IIRC, you need at least boot 1.4 in order to make the dependency management plugin work with gradle 3).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.