Search code examples
spring-bootopenshiftconsul

Connect to Consul server running openshift to consul client running on localhost


When I run consul on my local machine and spring boot client with following properties in bootstrap.properties, I can see that it connects, discovers services and able to connect from one service to other using service discovery. Bootstrap.properties:

spring.cloud.consul.host=localhost
spring.cloud.consul.port=8500
spring.cloud.consul.discovery.instance-id=consul-service2
spring.application.name=consul-service2
server.port=8083

But now, I installed consul on openshift provided route to it. I can browse to consul UI and see that consul service has registered itself. But when I try to connect client running on localhost to consul running on openshift i get error.

com.ecwid.consul.transport.TransportException: org.apache.http.conn.ConnectTimeoutException: Connect to consul-uservices-template.f-az.uk.paas.intranet.db.com:8500 [consul-uservices-template.hju-azh.uk.paas.intranet.sdf.com/10.248.36.85] failed: connect timed out
        at com.ecwid.consul.transport.AbstractHttpTransport.executeRequest(AbstractHttpTransport.java:77) ~[consul-api-1.4.1.jar:na]
        at com.ecwid.consul.transport.AbstractHttpTransport.makePutRequest(AbstractHttpTransport.java:41) ~[consul-api-1.4.1.jar:na]
        at com.ecwid.consul.v1.ConsulRawClient.makePutRequest(ConsulRawClient.java:135) ~[consul-api-1.4.1.jar:na]
        at com.ecwid.consul.v1.agent.AgentConsulClient.agentServiceRegister(AgentConsulClient.java:273) ~[consul-api-1.4.1.jar:na]
        at com.ecwid.consul.v1.ConsulClient.agentServiceRegister(ConsulClient.java:309) ~[consul-api-1.4.1.jar:na]

My bootstrap.properties:

spring.cloud.consul.host=consul-uservices-template.hju-azh.uk.paas.intranet.sdf.com
spring.cloud.consul.port=8500
spring.cloud.consul.discovery.instance-id consul-service2
spring.application.name=consul-service2
server.port=8083

What i am doing is providing route path as host, am I wrong here ? I can see that it tries to connect to consul-uservices-template.hju-azh.uk.paas.intranet.sdf.com:8500 and it times out. I get 404 even on browser when i try to hit this url. It should not be accessing with port number. How can i do that ?


Solution

  • It should not be accessing with port number.

    As the route is provided via OpenShift (and you can access it the web UI too), I assume it is accessible through port 80.

    If that is the case, you can specify spring boot to access consul via port 80 by change the following properties

    spring.cloud.consul.port=80