spring-cloud-netflix icon indicating copy to clipboard operation
spring-cloud-netflix copied to clipboard

Zuul proxy unable to resolve routes and forward the request to particular micro-service !!

Open GursharanKhalsa opened this issue 7 years ago • 5 comments

I'm getting 404 exceptions when I hit Zuul server to access the microservice.

Servers:

  1. Eureka Server (for service registry and discovery)
  2. Zuul Server (For Routing and load balancing)
  3. Notification Service (business microservice)

Zuul and notification service both connect with Eureka Server.

Requirement:

  1. Access notification service via Zuul and Zuul also handle load balancing on itself.

Please let me know how to resolve this issue and handle routes with load balancing on Zuul Server.

Zuul Server Exception:


2019-02-13 16:43:52.296  INFO 1840 --- [nio-8079-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2019-02-13 16:43:52.303  INFO 1840 --- [nio-8079-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 7 ms
Request Method : POST Request URL : http://192.168.11.27:8079/SIMS/notification-service/v1/endpointhandler/get/56/0
Using Route Filter
2019-02-13 16:43:52.507  INFO 1840 --- [nio-8079-exec-1] c.netflix.config.ChainedDynamicProperty  : Flipping property: NOTIFICATION-SERVICE-V1.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2019-02-13 16:43:52.527  INFO 1840 --- [nio-8079-exec-1] c.n.u.concurrent.ShutdownEnabledTimer    : Shutdown hook installed for: NFLoadBalancer-PingTimer-NOTIFICATION-SERVICE-V1
2019-02-13 16:43:52.528  INFO 1840 --- [nio-8079-exec-1] c.netflix.loadbalancer.BaseLoadBalancer  : Client: NOTIFICATION-SERVICE-V1 instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=NOTIFICATION-SERVICE-V1,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
2019-02-13 16:43:52.533  INFO 1840 --- [nio-8079-exec-1] c.n.l.DynamicServerListLoadBalancer      : Using serverListUpdater PollingServerListUpdater
2019-02-13 16:43:52.550  INFO 1840 --- [nio-8079-exec-1] c.netflix.config.ChainedDynamicProperty  : Flipping property: NOTIFICATION-SERVICE-V1.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2019-02-13 16:43:52.551  INFO 1840 --- [nio-8079-exec-1] c.n.l.DynamicServerListLoadBalancer      : DynamicServerListLoadBalancer for client NOTIFICATION-SERVICE-V1 initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=NOTIFICATION-SERVICE-V1,current list of Servers=[192.168.11.27:2020],Load balancer stats=Zone stats: {defaultzone=[Zone:defaultzone;	Instance count:1;	Active connections count: 0;	Circuit breaker tripped count: 0;	Active connections per server: 0.0;]
},Server stats: [[Server:192.168.11.27:2020;	Zone:defaultZone;	Total Requests:0;	Successive connection failure:0;	Total blackout seconds:0;	Last connection made:Thu Jan 01 05:30:00 IST 1970;	First connection made: Thu Jan 01 05:30:00 IST 1970;	Active Connections:0;	total failure count in last (1000) msecs:0;	average resp time:0.0;	90 percentile resp time:0.0;	95 percentile resp time:0.0;	min resp time:0.0;	max resp time:0.0;	stddev resp time:0.0]
]}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList@4507e1dd
Using Post Filter
2019-02-13 16:43:53.536  INFO 1840 --- [erListUpdater-0] c.netflix.config.ChainedDynamicProperty  : Flipping property: NOTIFICATION-SERVICE-V1.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
2019-02-13 16:48:47.489  INFO 1840 --- [trap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver      : Resolving eureka endpoints via configuration

Zuul Configuration:


eureka:
  client:
    serviceUrl:
      defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
#     New
    healthcheck:
      enabled: true
  instance:
    preferIpAddress: true
    #     New
    statusPageUrlPath: ${server.servlet.context-path}/actuator/info
    healthCheckUrlPath: ${server.servlet.context-path}/actuator/health    
    
server:
  port: 8079
  servlet:
    context-path: /SIMS
    
spring:
  application:
    name: ROUTER-SERVICE
zuul:
  routes:
    notification-service:
      path: '/notification-service/v1/**/**/**/**'
      service-id: NOTIFICATION-SERVICE-V1

Notification Service Config: (Which I want to access via Zuul)


eureka:
  client:
    serviceUrl:
      defaultZone: ${EUREKA_URI:http://localhost:8761/eureka}
#     New
    healthcheck:
      enabled: true
  instance:
    preferIpAddress: true
    #     New
    statusPageUrlPath: ${server.servlet.context-path}/actuator/info
    healthCheckUrlPath: ${server.servlet.context-path}/actuator/health

Notification Service Controller:


@RestController
@RefreshScope
@RequestMapping("/endpointhandler")
public class NSController {

	@RequestMapping(value="/get/{queryId}/{tenantId}" , method=RequestMethod.POST)
	public ServiceResponse get(@RequestBody String data, @PathVariable("queryId") long queryId, @PathVariable("tenantId") long tenantId) { 

		ServiceResponse response = new ServiceResponse();
		try {
			// Bussiness Login
			response.setStatus(ResponseConstants.SUCCESS);
			response.setData( requestHandler.getResultList());
					
		} catch (Exception e) {
			response.setStatus(ResponseConstants.FAIL);
			response.setErrorMsg(e.getMessage());
		}
		return response;
	}
}

GursharanKhalsa avatar Feb 13 '19 12:02 GursharanKhalsa

Is this ip address and port correct for the notification service 192.168.11.27:2020? This does not seem like a problem with zuul.
Can you provide a complete, minimal, verifiable sample that reproduces the problem? It should be available as a GitHub (or similar) project or attached to this issue as a zip file.

ryanjbaxter avatar Feb 13 '19 15:02 ryanjbaxter

Yes, this is the correct IP address and port for where the notification service is running.

GursharanKhalsa avatar Feb 13 '19 15:02 GursharanKhalsa

@GursharanKhalsa Please provide the sample, as requested above by @ryanjbaxter .

OlgaMaciaszek avatar Feb 13 '19 15:02 OlgaMaciaszek

@OlgaMaciaszek @ryanjbaxter You can find the code sample on following git repository: https://github.com/GursharanKhalsa/spring-cloud-eureka-zuul

GursharanKhalsa avatar Feb 14 '19 08:02 GursharanKhalsa

Finally, The issue has resolved. Actually, I defined a context path in hello-service but Zuul didn't add the prefix path with uri.

hello-service

server:
  port: 2020
  servlet:
    context-path: /SIMS/hello-service/v1

Zuul-service

zuul:
  ignoredServices: '*'
  routes:
    hello-service:
      path: /SIMS/hello-service/v1/**
      service-id: hello-service
      strip-prefix: false // if I comment this line then the error would occur 

GursharanKhalsa avatar Feb 19 '19 06:02 GursharanKhalsa