Reputation: 171
In a nutshell:
feign client tries to call http://MyApp/endpoint instead of http://10.0.1.24:8080/endpoint
I have an application with instances in AWS registering to an Eureka server and a feign client on the same Eureka server trying to communicate with the application (server is also client of itself if you will).
This is an sample of the /eureka/apps output on the server:
<application>
<name>JSAPI</name>
<instance>
<hostName>10.0.1.24</hostName>
<app>JSAPI</app>
<ipAddr>10.0.1.24</ipAddr>
<status>UP</status>
<overriddenstatus>UNKNOWN</overriddenstatus>
<port enabled="true">8080</port>
<securePort enabled="false">443</securePort>
<countryId>1</countryId>
<dataCenterInfo class="com.netflix.appinfo.AmazonInfo">
<name>Amazon</name>
<metadata>
<public-ipv4>52.91.157.255</public-ipv4>
<accountId>831427253318</accountId>
<local-hostname>10.0.1.24</local-hostname>
<public-hostname>ec2-52-91-157-255.compute-1.amazonaws.com</public-hostname>
<instance-id>i-1f86e68c</instance-id>
<local-ipv4>10.0.1.24</local-ipv4>
<instance-type>m4.large</instance-type>
<vpc-id>vpc-3c5e155b</vpc-id>
<ami-id>ami-ee5737f9</ami-id>
<mac>0e:3c:e0:fa:3f:1c</mac>
<availability-zone>us-east-1a</availability-zone>
</metadata>
</dataCenterInfo>
<leaseInfo>
<renewalIntervalInSecs>30</renewalIntervalInSecs>
<durationInSecs>90</durationInSecs>
<registrationTimestamp>1478146401223</registrationTimestamp>
<lastRenewalTimestamp>1478152383740</lastRenewalTimestamp>
<evictionTimestamp>0</evictionTimestamp>
<serviceUpTimestamp>1478146378932</serviceUpTimestamp>
</leaseInfo>
<metadata class="java.util.Collections$EmptyMap"/>
<homePageUrl>http://10.0.1.24:8080/</homePageUrl>
<statusPageUrl>http://10.0.1.24:8080/info</statusPageUrl>
<healthCheckUrl>http://10.0.1.24:8080/health</healthCheckUrl>
<vipAddress>JSAPI</vipAddress>
<secureVipAddress>JSAPI</secureVipAddress>
<isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
<lastUpdatedTimestamp>1478146401223</lastUpdatedTimestamp>
<lastDirtyTimestamp>1478110734306</lastDirtyTimestamp>
<actionType>ADDED</actionType>
</instance>...
The client code is like so:
@FeignClient("JSAPI")
public interface JsapiCustomerClient {
@RequestMapping(method = RequestMethod.POST, value = "/customers")
public void createCustomer(@Valid @RequestBody CustomerConfig customer);
}
I get the following error when trying to execute the method:
Connection refused executing POST http://JSAPI/customers
I expected it to try and call POST http://10.0.1.24:8080/customers
Any clue? This works on my local, fails once in the cloud.
Thanks
EDIT: Adding pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.knetikcloud</groupId>
<artifactId>clustermanager</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>clustermanager-server</artifactId>
<name>clustermanager-server</name>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>com.knetikcloud</groupId>
<artifactId>clustermanager-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-oauth2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.45</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-acm</artifactId>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- Packages the application to run in Elastic Beanstalk -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptor>assembly/beanstalk.xml</descriptor>
<finalName>${project.name}</finalName>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<description>A Eureka server paired with JSAPI apps specific status endpoints. The server is used to manage instance and customer status within a JSAPI cluster.</description>
</project>
Upvotes: 1
Views: 5781
Reputation: 3475
Could you post your eureka-client settings?
I believe you would need to set @FeignClient
's name (JSAPI in this case) to a mapping in application.yml (or .properties) and not to the service name.
I recently blogged about Service registration and discovery using Spring Cloud, Eureka, Ribbon, Feign, ... but here is an extract of the accompanying source code:
@FeignClient(name = ActorsClient.ACTORS_SERVIDE_ID)
public interface ActorsClient {
String ACTORS_SERVIDE_ID = "the-demo-registration-api-1";
String ACTORS_ENDPOINT = "/actors";
String ACTOR_BY_ID_ENDPOINT = "/actors/{id}";
...
Demo Service 2’s application.yml
...
eureka:
client:
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://localhost:8000/eureka/
instance:
hostname: ${hostName}
statusPageUrlPath: ${management.context-path}/info
healthCheckUrlPath: ${management.context-path}/health
preferIpAddress: true
metadataMap:
instanceId: ${spring.application.name}:${server.port}
...
the-demo-registration-api-1:
ribbon:
# Eureka vipAddress of the target service
DeploymentContextBasedVipAddresses: demo-registration-api-1
#listOfServers: localhost:${SERVER.PORT}
NIWSServerListClassName: com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList
# Interval to refresh the server list from the source (ms)
ServerListRefreshInterval: 30000
...
You could see the-demo-registration-api-1
is a key in yml file mapped to a registered service with name: demo-registration-api-1
Upvotes: 1
Reputation: 1945
You can specify eureka.instance.preferIpAddress
in your Eureka configuration then the ip instead of the hostname will be used.
If you want to use hostnames you can specify eureka.instance.hostname: ${vcap.application.uris[0]}
for example from environment.
More info: http://cloud.spring.io/spring-cloud-static/Brixton.SR6/#_eureka_metadata_for_instances_and_clients
Upvotes: 0