项目作者: dev-otitarenko

项目描述 :
Simple microservices project with docker, angular, eureka-server, eureka-client, auth server and resource server,
高级语言: Java
项目地址: git://github.com/dev-otitarenko/microservices-sample-auth-zuul-angular.git


Description

Sample of using microservices in docker containers. Used libraries: OAuth, Security, OpenFeign, Zuul, Lombok.
All services are logging in ELK stack.

  1. @Component
  2. public class AuthRequestInterceptor implements RequestInterceptor {
  3. @Override
  4. public void apply(RequestTemplate requestTemplate) {
  5. Authentication _auth = SecurityContextHolder.getContext().getAuthentication();
  6. if (_auth != null) {
  7. if (_auth.getDetails() instanceof OAuth2AuthenticationDetails) {
  8. String _token = ((OAuth2AuthenticationDetails) _auth.getDetails()).getTokenValue();
  9. requestTemplate.header("Authorization", String.format("Bearer %s", _token));
  10. }
  11. }
  12. }
  13. }

Installing ELK

Before running your application you should start Elastic Stack tools on your machine.
The best way (simply way) to do that is through Docker.
Firstly, let’s create the network:

  1. $ docker network create app_net

Secondly, let’s run ElasticSearch:

  1. $ docker run -d --name elasticsearch --net app_net -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:latest

In next step, let’s run Logbash:

  1. ocker run -d --name logstash --net app_net -p 5000:5000 -v ~/logstash.conf:/usr/share/logstash/pipeline/logstash.conf docker.elastic.co/logstash/logstash:latest
  1. input {
  2. tcp {
  3. port => 5000
  4. codec => json
  5. }
  6. }
  7. output {
  8. elasticsearch {
  9. hosts => ["http://elasticsearch:9200"]
  10. index => "micro-%{appname}"
  11. }
  12. }

Finally, let’s run Kibana:

  1. 1
  2. $ docker run -d --name kibana --net app_net -e "ELASTICSEARCH_URL=http://elasticsearch:9200" -p 5601:5601 docker.elastic.co/kibana/kibana:latest

Alternative way of installing ELK

[https://github.com/deviantony/docker-elk#how-to-configure-elasticsearch]

Running db

  1. docker-compose -f ./docker-compose-db.yml up -d --build

or

  1. sh ./build-db.sh

Running the application

  1. mvn clean package
  2. docker-compose -f ./docker-compose.yml up -d --build

or

  1. sh ./build-dev.sh

Application Endpoints

Service Port Endpoint
Eureka 8761 http://localhost:8761/
AuthService 8811 http://localhost:8811/oauth/
Service1 8812 http://localhost:8812/svc1/
Service2 8813 http://localhost:8813/svc2/
GatewayService 8810 http://localhost:8810/api/