Search code examples
spring-cloudnetflix-zuulspring-cloud-netflix

Zuul cannot connect to Eureka


I have a Eureka server running ok and a service connecting to it.
Now, I'm trying to connect a Zuul server to Eureka, but it isn't working.
I configure Zuul like this:

zuul:
  ignoredServices: "*"
  routes:
    contacts-service: 
      path: /contacts/**
      serviceId: contacts-service

eureka:
  instance:
    preferIpAddress: true
  client:
    serviceUrl:
      defaultZone: http://eureka:admin@127.0.0.1:8761/eureka/

and my class as

@SpringBootApplication
@EnableZuulServer
@EnableDiscoveryClient
public class EdgeApplication {

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

It never show in eureka neither nothing on the zuul logs eureka-related. Seems like I'm still missing something.

Edit

When I changed to @EnableZuulProxy, I get an error and the zuul service is still not shown at Eureka server

2016-10-06 23:26:46.574  WARN 8303 --- [nio-8080-exec-3] o.s.c.n.z.filters.post.SendErrorFilter   : Error during filtering

com.netflix.zuul.exception.ZuulException: Forwarding error
    at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.handleException(RibbonRoutingFilter.java:164) ~[spring-cloud-netflix-core-1.2.0.RELEASE.jar:1.2.0.RELEASE]
    at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.forward(RibbonRoutingFilter.java:139) ~[spring-cloud-netflix-core-1.2.0.RELEASE.jar:1.2.0.RELEASE]
    at org.springframework.cloud.netflix.zuul.filters.route.RibbonRoutingFilter.run(RibbonRoutingFilter.java:84) ~[spring-cloud-netflix-core-1.2.0.RELEASE.jar:1.2.0.RELEASE]
    at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:112) ~[zuul-core-1.2.2.jar:1.2.2]
    at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:197) ~[zuul-core-1.2.2.jar:1.2.2]
    at com.netflix.zuul.FilterProcessor.runFilters(FilterProcessor.java:161) ~[zuul-core-1.2.2.jar:1.2.2]
    at com.netflix.zuul.FilterProcessor.route(FilterProcessor.java:120) ~[zuul-core-1.2.2.jar:1.2.2]
    at com.netflix.zuul.ZuulRunner.route(ZuulRunner.java:96) ~[zuul-core-1.2.2.jar:1.2.2]
    at com.netflix.zuul.http.ZuulServlet.route(ZuulServlet.java:116) ~[zuul-core-1.2.2.jar:1.2.2]
    at com.netflix.zuul.http.ZuulServlet.service(ZuulServlet.java:81) ~[zuul-core-1.2.2.jar:1.2.2]
    at org.springframework.web.servlet.mvc.ServletWrappingController.handleRequestInternal(ServletWrappingController.java:157) [spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.cloud.netflix.zuul.web.ZuulController.handleRequestInternal(ZuulController.java:43) [spring-cloud-netflix-core-1.2.0.RELEASE.jar:1.2.0.RELEASE]

Edit 2

From time to time, I see this in the eureka server logs (not sure if its related or not to my problem, tho):

2016-10-06 23:52:32.824 ERROR 7053 --- [et_localhost-14] c.n.e.cluster.ReplicationTaskProcessor   : Batch update failure with HTTP status code 401; discarding 1 replication tasks
2016-10-06 23:52:32.825  WARN 7053 --- [et_localhost-14] c.n.eureka.util.batcher.TaskExecutors    : Discarding 1 tasks of TaskBatchingWorker-target_localhost-14 due to permanent error
2016-10-06 23:52:38.279  INFO 7053 --- [a-EvictionTimer] c.n.e.registry.AbstractInstanceRegistry  : Running the evict task with compensationTime 1ms

and right after I call the `/contacts/ endpoint, I see this in the zuul proxy logs:

2016-10-06 23:52:50.256  INFO 9346 --- [nio-8080-exec-1] c.n.u.concurrent.ShutdownEnabledTimer    : Shutdown hook installed for: NFLoadBalancer-PingTimer-contacts-service
2016-10-06 23:52:50.309  INFO 9346 --- [nio-8080-exec-1] c.netflix.loadbalancer.BaseLoadBalancer  : Client:contacts-service instantiated a LoadBalancer:DynamicServerListLoadBalancer:{NFLoadBalancer:name=contacts-service,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
2016-10-06 23:52:50.316  INFO 9346 --- [nio-8080-exec-1] c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
2016-10-06 23:52:50.322  INFO 9346 --- [nio-8080-exec-1] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client contacts-service initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=contacts-service,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:com.netflix.loadbalancer.ConfigurationBasedServerList@29851ac8
2016-10-06 23:52:50.785  WARN 9346 --- [nio-8080-exec-1] o.s.c.n.z.filters.post.SendErrorFilter   : Error during filtering

Solution

  • You are missing following dependency in your zuul service:

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>