Spring cloud 使用应用程序名而不是主机名假装客户端构建URL

Spring cloud 使用应用程序名而不是主机名假装客户端构建URL,spring-cloud,netflix-feign,Spring Cloud,Netflix Feign,简言之: 假装客户端尝试呼叫而不是 我有一个应用程序,其中AWS中的实例注册到Eureka服务器,同一Eureka服务器上的一个外部客户端尝试与该应用程序通信(如果愿意,服务器本身也是客户端) 这是服务器上的/eureka/apps输出示例: <application> <name>JSAPI</name> <instance> <hostName>10.0.1.24</ho

简言之:

假装客户端尝试呼叫而不是

我有一个应用程序,其中AWS中的实例注册到Eureka服务器,同一Eureka服务器上的一个外部客户端尝试与该应用程序通信(如果愿意,服务器本身也是客户端)

这是服务器上的/eureka/apps输出示例:

<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>...
我在尝试执行该方法时遇到以下错误:

Connection refused executing POST http://JSAPI/customers
我以为它会试着给邮局打电话

有线索吗?这在我的本地计算机上有效,在云中失败一次

谢谢

编辑:添加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>

4.0.0
com.knetikcloud
俱乐部经理
0.0.1-快照
clustermanager服务器
clustermanager服务器
org.springframework.cloud
SpringCloudStarterEureka服务器
com.knetikcloud
clustermanager核心
0.0.1-快照
org.springframework.boot
弹簧启动安全
org.springframework.cloud
spring云配置服务器
mysql
mysql连接器java
org.springframework.boot
弹簧靴启动器jdbc
org.springframework.cloud
spring-cloud-starter-oauth2
org.springframework.cloud
春云起动器
亚马逊网站
aws java sdk
1.11.45
org.json
json
亚马逊网站
aws java sdk acm
回写
回归经典
org.springframework.boot
spring启动程序数据mongodb
org.springframework.boot
springbootmaven插件
org.apache.maven.plugins
maven汇编插件
程序集/beanstalk.xml
${project.name}
包裹
单一的
与JSAPI应用程序特定状态端点配对的Eureka服务器。服务器用于管理JSAPI集群中的实例和客户状态。

您可以在eureka配置中指定
eureka.instance.preferIpAddress
,然后使用ip而不是主机名

如果要使用主机名,可以指定
eureka.instance.hostname:${vcap.application.uris[0]}
,例如从环境中指定

更多信息:

您可以在eureka配置中指定
eureka.instance.preferIpAddress
,然后使用ip而不是主机名

如果要使用主机名,可以指定
eureka.instance.hostname:${vcap.application.uris[0]}
,例如从环境中指定

更多信息:

您可以发布您的eureka客户端设置吗

我相信您需要将
@FeignClient
的名称(本例中为JSAPI)设置为application.yml(或.properties)中的映射,而不是服务名称

我最近写了一篇博客,但下面是附带的源代码摘录:

@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}";
...
演示服务2的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
 ...

您可以看到
demo-registration-api-1
是映射到注册服务的yml文件中的一个密钥,名称为:
demo-registration-api-1

您可以发布您的eureka客户端设置吗

我相信您需要将
@FeignClient
的名称(本例中为JSAPI)设置为application.yml(或.properties)中的映射,而不是服务名称

我最近写了一篇博客,但下面是附带的源代码摘录:

@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}";
...
演示服务2的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
 ...

您可以看到
demo-registration-api-1
是映射到注册服务的yml文件中的一个密钥,名称为:
demo-registration-api-1

您是否可以显示您的依赖项?哪些依赖项?您的应用程序(pom.xml或build.gradle)中没有任何版本的spring cloud。配置服务器和eureka服务器一起有哪些?spring cloud始终包括spring-cloud-starter-oauth2、spring cloud starter Faign、spring cloud starter eureka服务器、,等等。我的客户端和服务器在同一台服务器上,因为此应用程序旨在将设置传达给已注册的应用程序,并且应用程序可以在应用设置时回拨确认。因此,当此服务尝试与JSAPI应用程序通信时,它会尝试访问而不是显示没有任何spring cloud版本的应用程序(pom.xml或build.gradle)的依赖关系?哪些依赖关系。配置服务器和eureka服务器一起有哪些?spring cloud始终包括spring-cloud-starter-oauth2、spring cloud starter Faign、spring cloud starter eureka服务器、,等等。我的客户端和服务器在同一台服务器上,因为此应用程序旨在将设置传达给已注册的应用程序,并且应用程序可以在应用设置时回拨确认。因此,当这个服务尝试与JSAPI应用程序通信时,它会尝试访问,而不是我在AWS上运行的vcap。我不明白的是,注册表似乎很好。主机名和ip是一样的,所以我用哪一个都不重要。我不明白为什么会把主机名和应用程序名/vipAddress(JSAPI)混淆起来。它甚至没有尝试添加端口。。。10.0.1.24 JSAPI 10.0.1.24vcap是cloudfoundry,我在AWS上运行。我不明白的是注册处