需要帮助配置zuul +功能区

时间:2016-04-04 22:05:05

标签: java spring spring-cloud netflix-zuul netflix-ribbon

我需要帮助通过Spring Boot with Zuul配置Ribbon(负载平衡)。您可以在下面找到我的配置。

最初,我会分享我目前的架构以及我想要达到的目标:

  • 我有一个带网关的节点(Spring boot + zuul + ribbon)
  • 我还有另外两个节点将部署我的可扩展服务

Zuul配置:

zuul.routes.outlets.path=/outlets/**
zuul.routes.outlets.serviceId=outlets

outlets.ribbon.listOfServers=http://11.11.111.125:8092,http://11.11.111.126:8093
ribbon.eureka.enabled=false

据你所知没什么特别的。我的可伸缩服务具有以下配置:

@SpringBootApplication
@PropertySource
@RibbonClient(name = "outlets", configuration = RibbonClientConfiguration.class)
public class OutletsApplication {

    public static void main(String[] args) {
        SpringApplication.run(OutletsApplication.class, args);
    }
}

@Configuration
public class RibbonClientConfiguration {

    @Bean
    public IClientConfig config() {
        return new DefaultClientConfigImpl();
    }

    @Bean
    public IPing ribbonPing(IClientConfig config) {
        return new PingUrl();
    }
}

据我了解,它是一种非常常见的配置。

如果我直接向http://11.11.111.125:8092/outletshttp://11.11.111.126:8093/outlets提出请求,一切正常。

但是当我向网关发出请求时,我收到了404.我在日志中可以看到:

Matching pattern:/outlets/**
Returning cached instance of singleton bean 'ribbonRestClient'
Zone aware logic disabled or there is only one zone
outlets using LB returned Server: 11.11.111.126:8093 for request /
RestClient sending new Request(GET: ) http://11.11.111.126:8093/
Get connection: {}->http://11.11.111.126:8093, timeout = 2000
[{}->http://11.11.111.126:8093] total kept alive: 2, total issued: 0, total allocated: 2 out of 200
Getting free connection [{}->http://11.11.111.126:8093][null]
Stale connection check
CookieSpec selected: ignoreCookies
Auth cache not set in the context
Target auth state: UNCHALLENGED
Proxy auth state: UNCHALLENGED
Attempt 1 to execute request
Sending request: GET / HTTP/1.1
 >> "GET / HTTP/1.1[\r][\n]"
 >> "accept-language: ru,en-US;q=0.8,en;q=0.6[\r][\n]"
 >> "x-forwarded-host: localhost:8080[\r][\n]"
 >> "x-forwarded-proto: http[\r][\n]"
 >> "x-forwarded-prefix: /outlets[\r][\n]"
 >> "upgrade-insecure-requests: 1[\r][\n]"
 >> "Accept-Encoding: gzip[\r][\n]"
 >> "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8[\r][\n]"
 >> "user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36[\r][\n]"
 >> "Netflix.NFHttpClient.Version: 1.0[\r][\n]"
 >> "X-netflix-httpclientname: outlets[\r][\n]"
 >> "Host: 11.11.111.126:8093[\r][\n]"
 >> "Connection: Keep-Alive[\r][\n]"
 >> "[\r][\n]"
>> GET / HTTP/1.1
>> accept-language: ru,en-US;q=0.8,en;q=0.6
>> x-forwarded-host: localhost:8080
>> x-forwarded-proto: http
>> x-forwarded-prefix: /outlets
>> upgrade-insecure-requests: 1
>> Accept-Encoding: gzip
>> accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
>> user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36
>> Netflix.NFHttpClient.Version: 1.0
>> X-netflix-httpclientname: outlets
>> Host: 11.11.111.126:8093
>> Connection: Keep-Alive
 << "HTTP/1.1 404 Not Found[\r][\n]"
 << "Server: Apache-Coyote/1.1[\r][\n]"
 << "Content-Type: text/html;charset=UTF-8[\r][\n]"
 << "Content-Language: ru[\r][\n]"
 << "Content-Length: 306[\r][\n]"
 << "Date: Mon, 04 Apr 2016 21:47:16 GMT[\r][\n]"
 << "[\r][\n]"
 Receiving response: HTTP/1.1 404 Not Found
 << HTTP/1.1 404 Not Found
 << Server: Apache-Coyote/1.1
 << Content-Type: text/html;charset=UTF-8
 << Content-Language: ru
 << Content-Length: 306
 << Date: Mon, 04 Apr 2016 21:47:16 GMT
 Connection can be kept alive indefinitely
 << "<html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Mon Apr 04 21:47:16 UTC 2016</div><div>There was an unexpected error (type=Not Found, status=404).</div><div>No message available</div></body></html>"

据我所知,服务请求并不包含路径/出口。或者可能是我的Ribbon客户端配置错了?

我对如何修复它没有任何想法。

有人可以帮我吗?

0 个答案:

没有答案