SpringCloud distribution center integrated Gitlab (xv)

A start configuring config service

  • config-server

    • pom.xml

      1  <dependency>
      2             <groupId>org.springframework.cloud</groupId>
      3             <artifactId>spring-cloud-config-server</artifactId>
      4         </dependency>
      5 6         <dependency>
      7             <groupId>org.springframework.cloud</groupId>
      8             <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
      9         </dependency>

       

    • application.yml

      1  # Name Service
       2  Spring:
       . 3    file application:
       . 4      name: config- Server
       . 5    Cloud:
       . 6      config:
       . 7        Server:
       . 8          Git:
       . 9            URI: HTTP: // 192.168.180.112/root/test.git 
      10            username: the root
       . 11            password : 19920220ljyp
       12 is            default - label: Master
       13 is  14 15 # service port number
       16 Server:
       . 17    port: 9100
       18 is . 19     20  # Specify the center address
       21  Eureka:
       22    Client:
       23      serviceUrl:
       24-        defaultzone: HTTP: // localhost: 8761 / Eureka /

       

    • Startup class

      1 @SpringBootApplication
      2 @EnableConfigServer
      3 public class ConfigServerApplication {
      4 5     public static void main(String[] args) {
      6         SpringApplication.run(ConfigServerApplication.class, args);
      7     }
      8 9 }
       
  • Configuring services on gitlab yml file

 

product-service.yml

 1 # eureka:
 2 #   client:
 3 #     serviceUrl:
 4 #       defaultZone: http://localhost:8761/eureka/
 5 #  instance:
 6 #    instance-id: product-service8080
 7 #    prefer-ip-address: true
 8  9 server:
10   port: 8771
11 spring:
12   application:
13     name: product-service
14   zipkin:
15     base-url: http://192.168.180.113:9411/
16   sleuth:
17     sampler:
18       probability: 1
19 20 info:
21   app.name: product-servic
22   company.name: www.topcheer.com
 

order-service.yml

. 1  Server:
 2    Port: 8781
 . 3  . 4 . 5 # specified address registry
 . 6 Eureka:
 . 7   Client:
 . 8     the serviceUrl:
 . 9        defaultzone: HTTP: // localhost: 8761 / Eureka / 10 . 11 # Name service
 12 is Spring:
 13 is   file application:
 14      name: order- -Service
 15   Redis:
 16      Port: 6379
 . 17      Host: 192.168.180.113
 18 is      timeout: 2000
 . 19   Zipkin:
 20 is     
           URL-Base: HTTP: // 192.168.180.113:9411/ 
21 is    Sleuth:
 22 is      Sampler:
 23 is        Probability:. 1
 24  25 ### Request Timeout configuration
 26 is Hystrix:
 27   Command:
 28 default :
 29       Execution:
 30         Isolation:
 31 is           Thread:
 32               timeoutInMilliseconds: 5000
 33 is Ribbon:
 34 is ## refers to the connection time used for the case of normal network conditions, both ends of the connection time spent.
35    ReadTimeout: 2000
 36 ## refers to a connection is established from the server to read the available resources with time.
37                 The ConnectTimeout: 3000
 38 is  Feign:
 39    Hystrix:
 40      Enabled: to true 
41 is  Management:
 42 is    Endpoints:
 43 is      Web:
 44 is        Exposure:
 45          the include: "*"
 46 is  47 48 # custom load balancing policy
 49 # product- -Service:
 50 # Ribbon:
 51 # NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule   

 

 

api-gateway.yml

. 1  Server:
 2    Port: 9001
 . 3  . 4 # Spring:
 . 5 # file application:
 . 6 # name: the API- Gateway
 . 7 . 8 . 9 10 . 11 # specified address registration center
 12 is # Eureka:
 13 is # Client:
 14 # the serviceUrl:
 15 # defaultzone: HTTP: // localhost: 8761 / Eureka / 16 . 17 Zuul:
 18 is   routes:
 . 19      Order-Service-: / apigateway / ** 20 is          
   
     -Service-Product: / apigateway1 / **
 21 is    sensitive-headers:
 22 is    # unified entrance above configuration, ignoring the other inlet
 23 is    # ignored-Patterns: / * --Service / **
 24  25 Hystrix:
 26 is   Command:
 27     default:
 28       Execution:
 29         Isolation:
 30           Thread:
 31 is              timeoutInMilliseconds: 5000
 32 Ribbon:
 33 is ## refers to the connection time used for the network under normal conditions, the ends of the connection time spent.
34 is   ReadTimeout: 2000
 35 ## refers to a connection is established from the server to read the available resources with time.
36   the ConnectTimeout: 5000
 37 [ Feign:
             38   hystrix:
39     enabled: true
40 

 

Test: can directly open yml (renamed: bootstrap.yml)

  • other service

     1 spring:
     2   application:
     3     name: product-service
     4   cloud:
     5     config:
     6       discovery:
     7         service-id: CONFIG-SERVER
     8         enabled: true
     9       label: master
    10 添加pom.xml
    11 
    12             <dependency>
    13                 <groupId>org.springframework.cloud</groupId>
    14                 <artifactId>spring-cloud-config-client</artifactId>
    15             </dependency>

     

Read the configuration can be found by config-server, it can be called normal.

 

Guess you like

Origin www.cnblogs.com/dalianpai/p/11728771.html