Git Product home page Git Product logo

microservices-examples's Introduction

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 cask 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" : "[email protected]", "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

microservices-examples's People

Contributors

cer 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

microservices-examples's Issues

Code formatting is incorrect at http://plainoldobjects.com/2014/05/05/building-microservices-with-spring-boot-part-2

example

<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>bootstrap</artifactId>
    <version>3.1.1</version>
</dependency>

<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>jquery-validation</artifactId>
    <version>1.11.1</version>
</dependency>

http://plainoldobjects.com/2014/05/05/building-microservices-with-spring-boot-part-2

getting error while building gradle

[root@ip-172-31-40-37 spring-boot-webapp]# ./gradlew build
Downloading http://services.gradle.org/distributions/gradle-2.11-all.zip

Exception in thread "main" java.lang.RuntimeException: java.io.IOException: Server returned HTTP response code: 403 for URL: http://services.gradle.org/distributions/gradle-2.11-all.zip
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:78)
at org.gradle.wrapper.Install.createDist(Install.java:47)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://services.gradle.org/distributions/gradle-2.11-all.zip
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1897)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1495)
at org.gradle.wrapper.Download.downloadInternal(Download.java:59)
at org.gradle.wrapper.Download.download(Download.java:45)
at org.gradle.wrapper.Install$1.call(Install.java:60)
at org.gradle.wrapper.Install$1.call(Install.java:47)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
... 3 more
[root@ip-172-31-40-37 spring-boot-webapp]# ^C
[root@ip-172-31-40-37 spring-boot-webapp]# gradlew.bat connectedInstrumentTest
-bash: gradlew.bat: command not found
[root@ip-172-31-40-37 spring-boot-webapp]#

Linking your Containers

Thanks for doing this sample project. I have been able to pull a few items from this project.

Wondering if you had considered linking your mongo and rabbitmq containers to your webservice. I was able to setup and hoping to share what I figured out.

Basically when you link to another container new environment variables are created with ip and port information in the new container.

With this information set you can define them in the application.properties files.

  spring.data.mongodb.host = ${MONGODB_PORT_27017_TCP_ADDR:127.0.0.1}

This is the repo I have this setup in for reference. Hope this helps

https://github.com/zachariahyoung/docker-rest

MongoDB Timeout error when using Register User

Hi,
First of all thank you for this excellent project !!
I am trying to run the spring-boot-restful-services project on a VirtualBox using Ubuntu 14.x as the host OS . The host IP I have used is localhost and I get this error with I run the register-user.sh script I run into this issue with MongoDB timeout .. Any ideas what could be the reason

[nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Timed out while waiting to connect after 10000 ms; nested exception is com.mongodb.MongoTimeoutException: Timed out while waiting to connect after 10000 ms] with root cause

Thanks,
Tarun

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.