Giter Site home page Giter Site logo

piomin / sample-spring-microservices Goto Github PK

View Code? Open in Web Editor NEW
564.0 32.0 932.0 111 KB

Many samples in different branches that shows how to create microservices with Spring Boot, Spring Cloud, Zipkin, Zuul, Eureka, Hystrix, Kubernetes, Elastic Stack and many more tools

Home Page: https://piotrminkowski.wordpress.com/

Java 91.42% Dockerfile 8.58%
zuul eureka spring-cloud spring-boot microservices hystrix spring-boot-admin kubernetes logstash kibana

sample-spring-microservices's Introduction

Microservices with Spring Cloud Demo Project Twitter

In this project I'm demonstrating you the most interesting features of Spring Cloud Project for building microservice-based architecture. Most of examples are based on Spring Boot 1.5.

⚠️ This repository contains examples of Spring Boot 1.5 and won't be updated. If you are looking for the repository with the latest versions of Spring Boot/Spring Cloud please refer to that: https://github.com/piomin/sample-spring-microservices-new. It is automatically updated to the latest versions of all frameworks and libraries.

Getting Started

Currently you may find here some examples of microservices implementation using different projects from Spring Cloud. All the examples are divided into the branches and described in a separated articles on my blog. Here's a full list of available examples:

  1. Introduction to Spring Cloud components like discovery with Eureka, load balancing with Ribbon, REST client Feign, API gataway with Zuul. The example is available in the branch master. A detailed description can be found here: Part 1: Creating microservice using Spring Cloud, Eureka and Zuul
  2. Introduction to Spring Cloud components used for microservices monitoring like Spring Cloud Sleuth and Zipkin. Integration with Logstash for sending logs to ELK. The example is available in the branch logstash. A detailed description can be found here: Part 2: Creating microservices – monitoring with Spring Cloud Sleuth, ELK and Zipkin
  3. Introduction to load balancing with Ribbon and Feign declarative HTTP client, circuit braker and fallback with Hystrix. The example is available in the branch hystrix. A detailed description can be found here: Part 3: Creating Microservices: Circuit Breaker, Fallback and Load Balancing with Spring Cloud
  4. Using tool Spring Boot Admin for managing and monitoring microservices-based system. The example is available in the branch admin. A detailed description can be found here: Monitoring Microservices With Spring Boot Admin
  5. Deploying and running Spring Boot microservices on Kubernetes including inter-service communication using Feign client and integration with database Mongo. The example is available in the branch kubernetes. A detailed description can be found here: Microservices with Kubernetes and Docker

Usage

In the most cases you need to have Maven, JDK8+ and Docker for running third-party software like Zipkin or Logstash. In the fifth example with Kubernetes you will have to run Minikube on your local machine. The best way to run the sample applications is with IDEs like IntelliJ IDEA or Eclipse.

How to Run

docker-compose up

If you want to change anything on any service(s), you need to build the service(s) you changed and then :

docker-compose build docker-compose up

How to Run

docker-compose down

Architecture

Our sample microservices-based system consists of the following modules:

  • gateway-service - a module that Spring Cloud Netflix Zuul for running Spring Boot application that acts as a proxy/gateway in our architecture.
  • config-service - a module that uses Spring Cloud Config Server for running configuration server in the native mode. The configuration files are placed on the classpath.
  • discovery-service - a module that depending on the example it uses Spring Cloud Netflix Eureka as an embedded discovery server.
  • account-service - a module containing the first of our sample microservices that allows to perform CRUD operation on in-memory repository of accounts
  • customer-service - a module containing the second of our sample microservices that allows to perform CRUD operation on in-memory repository of customers. It communicates with account-service.
  • zipkin-service - a module that runs embedded Zipkin instance.

The following picture illustrates the architecture described above.


In case of Kubernetes deployment we use only some of Spring Cloud components like Spring Cloud Feign or Sleuth without discovery or config server.

For similar examples of microservice applications with Spring Boot 2 you may refer to the repository https://github.com/piomin/sample-spring-microservices-new

sample-spring-microservices's People

Contributors

maneeshgithub1 avatar piomin avatar prakhasaxena19 avatar ramazansakin 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

sample-spring-microservices's Issues

Getting Loading.... on Hystrix Dashboard

Hi ,
I am trying your sample https://github.com/piomin/sample-spring-microservices/tree/hystrix . I updated this with Hoxton.RELEASE and springboot 2.2.4.RELEASE. (With only code change of removing Sleuth config AlwaysSampler (as coulkd not find in deps with latest change).
When I go to hystrix dashboard http://localhost:2222/hystrix and then type in http://localhost:3333/actuator/hystrix.stream and hit on Monitor Stream and I see
Loading ....

Looks like this spring-attic/hystrix-dashboard#5
Do you know how to fix
I see in logs of acount service
2020-02-13 16:12:15.753 INFO [account-service,ff3f4d0dc9340df9,ff3f4d0dc9340df9,false] 9431 --- [nio-2222-exec-3] ashboardConfiguration$ProxyStreamServlet :

Proxy opening connection to: http://localhost:3333/actuator/hystrix.stream

Also, first I made hystrix.stream enabled on customer but not effect
and then on account (I think it should be on account service side ) still no effect

application.yml
management:
  endpoints:
    web:
      exposure:
        include: hystrix.stream

[security] Error on visit "/uaa/login" request mapping

Hi, I check out branch "security" , build success and run Eureka/Gateway/Customer/Account/Authentication services.

Then visit to http://localhost:8765/api/customer that redirect to http://localhost:9999/uaa/login as expected. But I get follow error message on browser

Whitelabel Error Page

This application has no explicit mapping for /error, so you are seeing this as a fallback.

Wed Aug 02 22:21:20 CST 2017
There was an unexpected error (type=Internal Server Error, status=500).
Circular view path [login]: would dispatch back to the current handler URL [/uaa/login] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)

And found error message on Authentication Service :

2017-08-02 22:21:20.393 ERROR 37120 --- [nio-9999-exec-1] o.a.c.c.C.[.[.[.[dispatcherServlet]      : Servlet.service() for servlet [dispatcherServlet] in context with path [/uaa] threw exception [Circular view path [login]: would dispatch back to the current handler URL [/uaa/login] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)] with root cause

javax.servlet.ServletException: Circular view path [login]: would dispatch back to the current handler URL [/uaa/login] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
	at org.springframework.web.servlet.view.InternalResourceView.prepareForRendering(InternalResourceView.java:205) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
	at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:145) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
	at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1257) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.5.jar:8.5.5]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
	at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
	at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:105) ~[spring-boot-actuator-1.4.1.RELEASE.jar:1.4.1.RELEASE]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.5.jar:8.5.5]

It seem /uaa/login is not mapping correctly.

Zipkin services is not working

[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.5:jar (default-jar) @ zipkin-service ---
[INFO] Building jar: D:\Jhipster\sample-spring-microservices-master\zipkin-service\target\zipkin-service-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ zipkin-service ---
[INFO] Installing D:\Jhipster\sample-spring-microservices-master\zipkin-service\target\zipkin-service-1.0-SNAPSHOT.jar to C:\Users\Guruv.m2\repository\pl\piomin\zipkin-service\1.0-SNAPSHOT\zipkin-service-1.0-SNAPSHOT.jar
[INFO] Installing D:\Jhipster\sample-spring-microservices-master\zipkin-service\pom.xml to C:\Users\Guruv.m2\repository\pl\piomin\zipkin-service\1.0-SNAPSHOT\zipkin-service-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.816 s
[INFO] Finished at: 2017-12-14T22:35:05+05:30
[INFO] Final Memory: 29M/283M
[INFO] ------------------------------------------------------------------------

D:\Jhipster\sample-spring-microservices-master\zipkin-service>cd target

D:\Jhipster\sample-spring-microservices-master\zipkin-service\target>java -jar zipkin-service-1.0-SNAPSHOT.jar
no main manifest attribute, in zipkin-service-1.0-SNAPSHOT.jar

D:\Jhipster\sample-spring-microservices-master\zipkin-service\target>

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.