MicroServices with Spring: Difference between revisions

From My Limbic Wiki
Line 35: Line 35:
|  
|  
* Dependencies
* Dependencies
  spring-cloud-starter-netflix-eureka-server
  spring-cloud-starter-'''netflix-eureka-server'''
  spring-boot : web, test & devtools
  spring-boot : web, test & devtools
|
|
* Dependencies
* Dependencies
  groupId - org.springframework.cloud
  groupId - org.springframework.cloud
   spring-cloud-starter-netflix-eureka-client
   spring-cloud-starter-'''netflix-eureka-client'''
   spring-cloud-starter-netflix-zuul
   spring-cloud-starter-'''netflix-zuul'''
  groupId - fr.dalichamp.microservices.common
  groupId - '''com.microservices.common'''
   SpringEurekaCommon
   SpringEurekaCommon
  spring-boot : web, test, devtools & security  
  spring-boot : web, test, devtools & security  
Line 52: Line 52:
! scope="row"| Properties
! scope="row"| Properties
|
|
  '''# Name'''
  spring.application.'''name'''=eureka-server
spring.application.name=eureka-server
  server.'''port'''=8761
  '''# Default Port'''
  eureka.'''client.register-with-eureka=false'''
server.port=8761
  eureka.'''client.fetch-registry=false'''
  '''# Eureka server may not be a Client'''
eureka.client.register-with-eureka=false
  eureka.client.fetch-registry=false
|
|
  server.port=8762
  server.'''port'''=8762
  spring.application.name=zuul-server
  spring.application.'''name'''=zuul-server
  eureka.client.service-url.default-zone=http://localhost:8761/eureka/
  eureka.'''client.service-url.default-zone'''=http://localhost:8761/eureka/
  '''# A prefix that can added to beginning of all requests. '''
  #zuul.'''prefix'''=/api
'''#zuul.prefix=/api'''
* Disable accessing services using service name (i.e. gallery-service).
'''# Disable accessing services using service name (i.e. gallery-service).'''
  zuul.'''ignored-services=*'''
  zuul.ignored-services=*
* Map paths to services
'''# Map paths to services'''
  zuul.routes.'''gallery-service.path'''=/gallery/**
  zuul.routes.gallery-service.path=/gallery/**
  zuul.routes.'''gallery-service.service-id'''=gallery-service
  zuul.routes.gallery-service.service-id=gallery-service
  zuul.routes.'''auth-service.path'''=/auth/**
  zuul.routes.auth-service.path=/auth/**
  zuul.routes.'''auth-service.service-id'''=AUTH-SERVICE$
  zuul.routes.auth-service.service-id=AUTH-SERVICE$
* So, if request is "/gallery/view/1", gallery service will get "/view/1".
'''# So, if request is "/gallery/view/1", gallery service will get "/view/1".'''
  zuul.routes.'''auth-service.strip-prefix'''=false
  zuul.routes.auth-service.strip-prefix=false
  zuul.routes.'''auth-service.sensitive-headers'''=Cookie,Set-Cookie #Exclude authorization from sensitive headers
'''# Exclude authorization from sensitive headers'''
  zuul.routes.auth-service.sensitive-headers=Cookie,Set-Cookie  
|
|
   '''# service name'''
   spring.application.'''name'''=image-service
  spring.application.name=image-service
   server.'''port'''=8200
   '''# port'''
   eureka.client.service-'''url.default'''-zone=http://localhost:8761/eureka
  server.port=8200
  '''# eureka server url'''
   eureka.client.service-url.default-zone=http://localhost:8761/eureka
|-
|-
|}
|}

Revision as of 23:48, 20 September 2019

Vulgarization

Specificities in a Spring aborescence

Eureka

Is the registration service, all services will connect to the same adress: http://localhost:9000 for example

Fichiers Server Zuul Image & Gallery
Main
  • com.microservices.server.EurekaServerApplication.java
@SpringBootApplication
@EnableEurekaServer // Enable eureka server
  • com.microservices.zuul.EurekaZuulApplication.java
@SpringBootApplication
@EnableEurekaClient
@EnableZuulProxy
  • com.microservices.image.EurekaImageApplication.java
@SpringBootApplication
@EnableEurekaClient
  • com.microservices.image.controllers.ImageController.java
@RestController
@RequestMapping("/")
@Autowired
   private Environment env;
  • com.microservices.image.entities.Image.java
Pom.xml
  • Dependencies
spring-cloud-starter-netflix-eureka-server
spring-boot : web, test & devtools
  • Dependencies
groupId - org.springframework.cloud
  spring-cloud-starter-netflix-eureka-client
  spring-cloud-starter-netflix-zuul
groupId - com.microservices.common
  SpringEurekaCommon
spring-boot : web, test, devtools & security 
  • Dependencies
spring-cloud-starter-netflix-eureka-client
spring-boot : web, test & devtools
Properties
spring.application.name=eureka-server
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
server.port=8762
spring.application.name=zuul-server
eureka.client.service-url.default-zone=http://localhost:8761/eureka/
#zuul.prefix=/api
  • Disable accessing services using service name (i.e. gallery-service).
zuul.ignored-services=*
  • Map paths to services
zuul.routes.gallery-service.path=/gallery/**
zuul.routes.gallery-service.service-id=gallery-service
zuul.routes.auth-service.path=/auth/**
zuul.routes.auth-service.service-id=AUTH-SERVICE$
  • So, if request is "/gallery/view/1", gallery service will get "/view/1".
zuul.routes.auth-service.strip-prefix=false
zuul.routes.auth-service.sensitive-headers=Cookie,Set-Cookie  #Exclude authorization from sensitive headers
 spring.application.name=image-service
 server.port=8200
 eureka.client.service-url.default-zone=http://localhost:8761/eureka
Fichiers Common Auth
Main
  • com.microservices.
tofill
  • com.microservices.
tofill
Pom.xml
  • Dependencies
tofill
  • Dependencies
tofill
Properties
tofill
tofill