SpringCloud+Consul配置Zuul网关服务

转发的目标服务microservice-provider-user配置

server:
  port: 8000
spring:
  application:
    name: microservice-provider-user
  cloud:
    consul:
      discovery:
        instance-id: ${spring.application.name}:${server.port}
        prefer-ip-address: true
        healthCheckPath: /health
        healthCheckInterval: 15s
        hostname: ${spring.application.name}
        service-name: ${spring.application.name}
        enabled: true
        register: true
        heartbeat:
          enabled: true
      host: aliyun.lzh
      port: 8500  
      enabled: true

logging:                                # 配置日志级别,让hibernate打印出执行的SQL
  level:
    root: INFO
    org.hibernate: INFO
    org.hibernate.type.descriptor.sql.BasicBinder: TRACE
    org.hibernate.type.descriptor.sql.BasicExtractor: TRACE


  4.0.0
  com.itmuch.cloud
  microservice-gateway-zuul
  0.0.1-SNAPSHOT
  jar

  
  
    org.springframework.boot
    spring-boot-starter-parent
    1.5.9.RELEASE
  

  
    UTF-8
    1.8
  

  
    
      org.springframework.cloud
      spring-cloud-starter-netflix-zuul
    
    
      org.springframework.cloud
      spring-cloud-starter-consul-discovery
    
    
	org.springframework.boot
	spring-boot-starter-actuator

  

  
  
    
      
        org.springframework.cloud
        spring-cloud-dependencies
        Edgware.RELEASE
        pom
        import
      
    
  

  
  
    
      
        org.springframework.boot
        spring-boot-maven-plugin
      
    
  

package com.itmuch.cloud.study;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

@SpringBootApplication
@EnableZuulProxy
public class ZuulApplication {
  public static void main(String[] args) {
    SpringApplication.run(ZuulApplication.class, args);
  }
}

Zuul网关microservice-gateway-zuul 配置

server:
  port: 8040
spring:
  application:
    name: microservice-gateway-zuul
  cloud:
    consul:
      discovery:
        instance-id: ${spring.application.name}:${server.port}
        prefer-ip-address: true
        healthCheckPath: /health
        healthCheckInterval: 15s
        hostname: ${spring.application.name}
        service-name: ${spring.application.name}
        enabled: true
        register: true
        heartbeat:
          enabled: true
      host: aliyun.lzh
      port: 8500  
      enabled: true
      
management:
  security:
    enabled: false

zuul:
  ignored-services: '*'   # 使用'*'可忽略所有微服务
  routes:
    microservice-provider-user: /user/**
    
    
hystrix:
 command:
   default:
     execution:
       timeout:
         enabled: false
       isolation:
         thread:
           timeoutInMilliseconds: 60000

ribbon:
  ReadTimeout: 60000
  ConnectTimeout: 60000


	4.0.0
	com.itmuch.cloud
	microservice-provider-user
	0.0.1-SNAPSHOT
	jar

	
	
		org.springframework.boot
		spring-boot-starter-parent
		1.5.9.RELEASE
	

	
		UTF-8
		1.8
	

	
		
			org.springframework.boot
			spring-boot-starter-web
		

		
			com.h2database
			h2
		
		
			org.springframework.boot
			spring-boot-starter-actuator
		

		
			org.springframework.cloud
			spring-cloud-starter-consul-discovery
		

	

	
	
		
			
				org.springframework.cloud
				spring-cloud-dependencies
				Edgware.RELEASE
				pom
				import
			
		
	

遇到的问题:

请求接口http://localhost:8040/user/123 正常应该被zuul网关转发到microservice-provider-user服务的接口中但是测试过程中一直出现

com.netflix.client.ClientException: Load balancer does not have available server for client

 原因:zuul网关服务microservice-gateway-zuul 的健康检查服务没开启,


	org.springframework.boot
	spring-boot-starter-actuator
spring.cloud.consul.heartbeat.enabled = true

spring.cloud.consul.healthCheckPath = /health 

spring.cloud.consul.healthCheckInterval = 15s

完整代码:

https://gitee.com/lzhcode/spring-cloud-docker-microservice-book-code/tree/master/microservice-gateway-zuul

https://gitee.com/lzhcode/spring-cloud-docker-microservice-book-code/tree/master/microservice-provider-user

你可能感兴趣的:(框架)