Examples of microservices
JavaScript Scala Shell Other
Switch branches/tags
Nothing to show
Clone or download
Permalink
Failed to load latest commit information.
e2e-test Various changes including Spring Cloud upgrade and improved instructi… May 31, 2016
eureka-server Misc improvements to docker-compose files Jul 30, 2017
spring-boot-restful-service Misc improvements to docker-compose files Jul 30, 2017
spring-boot-webapp Misc improvements to docker-compose files Jul 30, 2017
zipkin-server Misc improvements to docker-compose files Jul 30, 2017
.gitignore Added Vagrantfile Feb 26, 2016
LICENSE.txt Added LICENSE.txt Apr 1, 2014
README.md Added Spring Cloud Sleuth Sep 11, 2016
Vagrantfile Added Vagrantfile Feb 26, 2016
build-and-test-all.sh Added Spring Cloud Sleuth Sep 11, 2016
build-and-test-e2e.sh Fixed typo in script and cleaned up docker-compose.yml files Jun 7, 2016
build-docker-images.sh Misc improvements to docker-compose files Jul 30, 2017
build-test-and-run-all.sh Various changes including Spring Cloud upgrade and improved instructi… May 31, 2016
clean-all.sh Misc improvements to docker-compose files Jul 30, 2017
docker-compose-images.yml Misc improvements to docker-compose files Jul 30, 2017
docker-compose.yml Misc improvements to docker-compose files Jul 30, 2017
gradle-all.sh Added Spring Cloud Sleuth Sep 11, 2016
mongodb-cli.sh Various changes including Spring Cloud upgrade and improved instructi… May 31, 2016
register-user.sh Various changes including Spring Cloud upgrade and improved instructi… May 31, 2016
run-e2e-test-images.sh Added Spring Cloud Sleuth Sep 11, 2016
run-e2e-test.sh Added Spring Cloud Sleuth Sep 11, 2016
set-env.sh Added Spring Cloud Sleuth Sep 11, 2016
show-urls.sh Removed reference to non-existent Swagger UI for web front-end Sep 12, 2016
wait-for-running-system.sh Various changes including Spring Cloud upgrade and improved instructi… May 31, 2016
wait-for-services.sh Added Spring Cloud Sleuth Sep 11, 2016

README.md

A simple example of microservices that is described in this series of blog posts.

There are two services:

The services are written in Scala and use the following technologies.

  • Spring Boot
  • Spring Cloud
  • Netflix OSS Eureka
  • RabbitMQ

Note: There are other example microservice applications.

Building and running the microservices

This project uses with Docker Compose to run the services as well as RabbitMQ and MongoDB.

The spring-boot-webapp project uses Selenium to test the web UI using the Chrome browser. You will need to install ChromeDriver. On Mac OSX you can run brew install chromedriver.

The quick way

The quickest way to build and run the services on Linux/Mac OSX is with the following commands:

. ./set-env.sh
./gradle-all.sh assemble
docker-compose up -d
./show-urls.sh

Otherwise, follow these instructions.

Running MongoDB and RabbitMQ

The RESTful service uses RabbitMQ and MongoDB. The easier way to run them is to using Docker:

 docker-compose up -d mongodb rabbitmq

You also need to set some environment variables so that the services can connect to them:

export DOCKER_HOST_IP=$(docker-machine ip default 2>/dev/null)

export SPRING_DATA_MONGODB_URI=mongodb://${DOCKER_HOST_IP}/userregistration
export SPRING_RABBITMQ_HOST=${DOCKER_HOST_IP}

Build the Eureka server

This application uses Netflix OSS Eureka for service discovery. Build the Spring Cloud based Eureka server using the following commands:

cd eureka-server
./gradlew build

Build the Zipkin server

This application uses Zipkin for distributed tracing. Build the Zipkin server using the following commands:

cd zipkin-server
./gradlew build

Building the RESTful service

Use the following commands to build the RESTful service:

 cd spring-boot-restful-service
 ./gradlew build    

Running the RESTful service

You can run the service by using the following command in the top-level directory:

docker-compose up -d restfulservice

Using the RESTful service

Once the service has started, you can send a registration request using:

./register-user.sh

You can examine the MongoDB database using the following commands

$ ./mongodb-cli.sh
> show dbs;
local             0.031GB
mydb              0.031GB
userregistration  0.031GB
> use userregistration;
switched to db userregistration
>
>
> show collections;
registeredUser
system.indexes
>
>
> db.registeredUser.find()
{ "_id" : ObjectId("55a99b0993860551c6020e9d"), "_class" : "net.chrisrichardson.microservices.restfulspringboot.backend.RegisteredUser", "emailAddress" : "1437178632863-b-foo@bar.com", "password" : "secret" }
> exit
$

Building the web application

Since the web application invokes the RESTful service you must set the following environment variable:

export USER_REGISTRATION_URL=http://${DOCKER_HOST_IP}:8081/user

Next, use the following commands to build the web application:

cd spring-boot-webapp
./gradlew build

Running the web application

Run the web application using the following command in the top-level directory:

docker-compose up -d web

Using the web application

You can access the web application by visiting the following URL: http://${DOCKER_HOST_IP?}:8080/register.html

There are also other URLs that you can visit. The following command will wait until the services are available and displays the URLs:

./show-urls.sh

Building and running Docker images

The previous instructions deployed the services as Docker containers without actually packaging the services as Docker images. The docker-compose.yml file ran the image java:openjdk-8u91-jdk and used volume mapping to make the Spring Boot jar files accessible. Follow these instructions to build and run the Docker images.

Building the images

You can build the images by running the following command:

./build-docker-images.sh

This script is a simple wrapper around docker build.

Running the images

You can now run the Docker images using the docker-compose command with docker-compose-images.yml:

docker-compose -f docker-compose-images.yml up -d

The following command will wait until the services are available and displays the URLs:

./show-urls.sh