2

I have a Spring Cloud application (Eureka, Ribbon, Zuul) that runs perfectly locally in Spring Tools Suite. When I deploy to Pivotal Web Services, the services register with Eureka (i.e., they show up in the Eureka console), but when I try to have one service call another I get Connection refused. When I try to go through Zuul, I get Forwarding Error followed by Connection refused.

I've tried various combinations of the following, but nothing seems to help.

eureka:
 client:
  serviceUrl:
   defaultZone: http://myeurekaserver.cfapps.io/eureka/
 instance:
    preferIpAddress: true
#   hostname: ${CF_INSTANCE_IP:localhost}
#   nonSecurePort: ${CF_INSTANCE_PORT:${PORT:${server.port:8002}}}
    hostname: ${vcap.application.uris[0]}
    nonSecurePort: 80

For the service to service calls I use the Autowired RestTemplate. In another part of my code I use the non-Autowired RestTemplate. When I use that with discoveryClient.getInstances(...) I do get back the ip address and ports of my services. If I try to directly call those IP addresses/ports I also get Connection Refused.

Any ideas?

g00glen00b
  • 41,995
  • 13
  • 95
  • 133
Jim
  • 81
  • 1
  • 6
  • What is the exact exception you are getting? – user3272686 Feb 08 '17 at 16:51
  • When I invoke through Zuul I get com.netflix.zuul.exception.ZuulException: Forwarding error. Followed by - org.apache.http.conn.HttpHostConnectException: Connect to 10.241.130.173:80 [/10.241.130.173] failed: Connection refused. When I execute without Zuul (i.e., invoke a service directly that call another service) I just get the Connection refused. – Jim Feb 08 '17 at 18:25

2 Answers2

2

Found my own answer - In PWS, CF Networking has to be enabled. Then one needs to apply rules to let services talk directly to each other.

https://docs.cloudfoundry.org/adminguide/container-networking.html

Jim
  • 81
  • 1
  • 6
  • After enabling the container-to-container networking using `cf add-network-policy` as you did, you just need to set the `preferIpAddress: true` property. The two others are required when you DON'T want to use the container-to-container network. Using them, you are telling the applications to register with Eureka using their external URLs so that the connectivity goes through the [Gorouters](https://docs.cloudfoundry.org/concepts/architecture/router.html) PWS reverse proxies. – dbaltor Jul 13 '20 at 11:15
0

Try these suggestions:

  1. Restart the instance that runs Zuul and see if that solves the problem

  2. Try monitoring the counter.servo.discoveryclient* values in /metrics

g00glen00b
  • 41,995
  • 13
  • 95
  • 133
user3272686
  • 853
  • 2
  • 11
  • 23
  • I've restarted Zuul and all the other components many times. Here are the values in /metrics that I think you are referring to. This is from the service that uses discoveryClient: – Jim Feb 08 '17 at 20:23
  • "counter.servo.discoveryclient-httpclient_delete" : 5734 5821 5833 5841 "counter.servo.discoveryclient_reconcilehashcodemismatch" : 0 "counter.servo.discoveryclient-httpclient_request" : 5874 5962 5974 5982 "counter.servo.discoveryclient-httpclient_createnew" : 5736 5823 5835 5843 "counter.servo.discoveryclient-httpclient_reuse" : 138 139 "counter.servo.discoveryclient-httpclient_release" : 5874 5962 5974 5982 "counter.servo.discoveryclient_reregister" : 0 – Jim Feb 08 '17 at 20:24
  • Each counter value is for a subsequent run. For example the first run at the top was 5734, second run 5821, third 5833, etc. – Jim Feb 08 '17 at 20:26
  • Just changed eureka.instance.preferIpAddress to false. Now it finds the service, but is trying to invoke it by the instance ID - the value that shows up in the Eureka console. It is doing the lookup on http://myServiceLogicalName/pathInThatService. So, it is finding the right service, but can't invoke it by the instance ID. I get: java.net.UnknownHostException: f6795e60-5d38-4903-4a0b-82859baa1c90 – Jim Feb 09 '17 at 15:13
  • Just changed eureka.instance.preferIpAddress back to true. It seems to find the correct internal IP of 10.241.80.169:8080 for my service. Here is some more of the log: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error on POST request for..myServiceName...Connection refused; nested exception is java.net.ConnectException: Connection refused – Jim Feb 09 '17 at 15:25