带有 Wildfly 和部署顺序的 Eureka+Cloud-Config

Posted

技术标签:

【中文标题】带有 Wildfly 和部署顺序的 Eureka+Cloud-Config【英文标题】:Eureka+Cloud-Config with Wildfly and deployment order 【发布时间】:2018-12-01 19:57:07 【问题描述】:

我需要在 Wildfly 环境中集成一些 SpringBoot 服务。 有一个 Eureka-Server+Cloud Config-Service 作为 WAR 在 Wildfly 中运行。看不到仪表板,但是可以在..eureka/apps的XML数据中看到自注册服务 如果我以独立模式为 Eureka/Cloud Config 启动 SpringBoot 客户端 - 它会完美连接到此 Wildfly/Eureka/CloudConfig 服务。同样,当我将此客户端作为 WAR 添加到已经运行的 Wildfly/Eureka/CloudConfig 系统中时。

但是当我杀死服务器并重新启动它时,两个WAR的并行部署在启动过程中当然会产生很多异常。没关系,因为 Eureka Server 还没有启动。但在它之后 - 客户端将自己正确注册到 Eureka 服务器(我再次在 eureka/apps 中看到它)。但是客户端一直在发送异常。

2018-06-22 12:40:10,345 WARN  [org.springframework.cloud.config.client.DiscoveryClientConfigServiceBootstrapConfiguration] (DiscoveryClient-CacheRefreshExecutor-0) Could not locate configserver via discovery: java.lang.IllegalStateException: No instances found of configserver (EUREKA-DISCOVERY-SERVICE)
        at org.springframework.cloud.config.client.ConfigServerInstanceProvider.getConfigServerInstance(ConfigServerInstanceProvider.java:25)
        at org.springframework.cloud.config.client.DiscoveryClientConfigServiceBootstrapConfiguration.refresh(DiscoveryClientConfigServiceBootstrapConfiguration.java:80)
        at org.springframework.cloud.config.client.DiscoveryClientConfigServiceBootstrapConfiguration.heartbeat(DiscoveryClientConfigServiceBootstrapConfiguration.java:72)
        at sun.reflect.GeneratedMethodAccessor122.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:261)
        at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:180)
        at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:142)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:400)
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:406)
        at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:354)
        at org.springframework.cloud.netflix.eureka.CloudEurekaClient.onCacheRefreshed(CloudEurekaClient.java:112)
        at com.netflix.discovery.DiscoveryClient.fetchRegistry(DiscoveryClient.java:981)
        at com.netflix.discovery.DiscoveryClient.refreshRegistry(DiscoveryClient.java:1471)
        at com.netflix.discovery.DiscoveryClient$CacheRefreshThread.run(DiscoveryClient.java:1438)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)

每 30 秒(刷新时间)出现一次异常。 我不明白,为什么会这样。 ...eureka/apps 结果显示服务

<applications>
  <versions__delta>1</versions__delta>
  <apps__hashcode>UP_2_</apps__hashcode>
  <application>
    <name>EUREKA-DISCOVERY-SERVICE</name>
    <instance>
      <instanceId>192.168.207.94:eureka-discovery-service:8443</instanceId>
      <hostName>localhost</hostName>
      <app>EUREKA-DISCOVERY-SERVICE</app>
      <ipAddr>192.168.207.94</ipAddr>
      <status>UP</status>
      <overriddenstatus>UNKNOWN</overriddenstatus>
      <port enabled="false">80</port>
      <securePort enabled="true">8443</securePort>
      <countryId>1</countryId>
      <dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
        <name>MyOwn</name>
      </dataCenterInfo>
      <leaseInfo>
        <renewalIntervalInSecs>30</renewalIntervalInSecs>
        <durationInSecs>90</durationInSecs>
        <registrationTimestamp>1529662231729</registrationTimestamp>
        <lastRenewalTimestamp>1529663993904</lastRenewalTimestamp>
        <evictionTimestamp>0</evictionTimestamp>
        <serviceUpTimestamp>1529662210687</serviceUpTimestamp>
      </leaseInfo>
      <metadata>
        <management.port>8443</management.port>
        <configPath>/eureka-ds/config</configPath>
      </metadata>
      <homePageUrl>http://localhost:80/</homePageUrl>
      <statusPageUrl>http://localhost:8443/actuator/info</statusPageUrl>
      <healthCheckUrl>http://localhost:8443/actuator/health</healthCheckUrl>
      <secureHealthCheckUrl>https://localhost:8443/actuator/health</secureHealthCheckUrl>
      <vipAddress>eureka-discovery-service</vipAddress>
      <secureVipAddress>eureka-discovery-service</secureVipAddress>
      <isCoordinatingDiscoveryServer>true</isCoordinatingDiscoveryServer>
      <lastUpdatedTimestamp>1529662231729</lastUpdatedTimestamp>
      <lastDirtyTimestamp>1529662193289</lastDirtyTimestamp>
      <actionType>ADDED</actionType>
    </instance>
  </application>
  <application>
    <name>MARK2</name>
    <instance>
      <instanceId>192.168.207.94:mark2:9998</instanceId>
      <hostName>192.168.207.94</hostName>
      <app>MARK2</app>
      <ipAddr>192.168.207.94</ipAddr>
      <status>UP</status>
      <overriddenstatus>UNKNOWN</overriddenstatus>
      <port enabled="true">9998</port>
      <securePort enabled="false">443</securePort>
      <countryId>1</countryId>
      <dataCenterInfo class="com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo">
        <name>MyOwn</name>
      </dataCenterInfo>
      <leaseInfo>
        <renewalIntervalInSecs>30</renewalIntervalInSecs>
        <durationInSecs>90</durationInSecs>
        <registrationTimestamp>1529662210686</registrationTimestamp>
        <lastRenewalTimestamp>1529663979339</lastRenewalTimestamp>
        <evictionTimestamp>0</evictionTimestamp>
        <serviceUpTimestamp>1529662210687</serviceUpTimestamp>
      </leaseInfo>
      <metadata>
        <management.port>9998</management.port>
        <configPath>/eureka-ds/config</configPath>
        <user>user</user>
        <password>software1</password>
      </metadata>
      <homePageUrl>http://192.168.207.94:9998/</homePageUrl>
      <statusPageUrl>http://192.168.207.94:9998/actuator/info</statusPageUrl>
      <healthCheckUrl>http://192.168.207.94:9998/actuator/health</healthCheckUrl>
      <vipAddress>mark2</vipAddress>
      <secureVipAddress>mark2</secureVipAddress>
      <isCoordinatingDiscoveryServer>false</isCoordinatingDiscoveryServer>
      <lastUpdatedTimestamp>1529662210687</lastUpdatedTimestamp>
      <lastDirtyTimestamp>1529662208806</lastDirtyTimestamp>
      <actionType>ADDED</actionType>
    </instance>
  </application>
</applications>

【问题讨论】:

【参考方案1】:

这个答案可能对错误No instances found of configserver(configserver)有帮助,

Spring Cloud Config Server 的默认名称为“configserver”如果您在 application.properties 中使用 spring.application.name=my-config-server 覆盖此名称,则在 Config Client 应用程序的 bootstrap.properties 中您需要使用 spring.cloud.config.discovery.service-id=my-config-server

示例配置服务器

spring.application.name=my-config-server
eureka.instance.hostname=localhost
server.port=8888
spring.cloud.config.server.git.uri=file:////Users/asadhat/work/lab/spring-cloud
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/

示例配置客户端

spring.application.name=my-config-client
server.port=7000
eureka.instance.hostname=localhost
spring.cloud.config.discovery.enabled=true
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
spring.cloud.config.discovery.service-id=my-config-server

【讨论】:

【参考方案2】:

我找到了一种方法,让它发挥作用。

如果我设置 spring.cloud.config.fail-fast=false(这是默认设置),那么服务会进行多次重试。然后在引导期间服务发送错误,但是在配置服务器启动后,客户端服务注册并且一切正常。这需要几秒钟... 然后 - 我了解到,不要将 Eureka 服务器和 Cloud config 服务器放在一个服务中。即使减少最小化基础设施是一个好主意,云配置服务也有点棘手,需要完全访问 URL 路径。由于一个小错误(有一个拉取请求),即使定义前缀也不起作用。 第三 - 在 Wildfly 环境中正确定义 StatusPageURLPath 和 HealthCheckURLPath(见上文,这是错误的)

【讨论】:

以上是关于带有 Wildfly 和部署顺序的 Eureka+Cloud-Config的主要内容,如果未能解决你的问题,请参考以下文章

带有 PostgreSQL 9.4 数据源的 WildFly 10 部署应用程序时出错

如何在 Wildfly 中设置两只耳朵的部署顺序

Wildfly 10.1 部署后停止部署

安全域的 Wildfly 刷新缓存

当两个 jar 具有相同的类集时,使用 jboss/wildfly 的类加载冲突,如何设置顺序/优先级?

在 WildFly 上重新部署后,CDI 无法在 @Requestscoped REST 服务中将 @Singleton 设置为 @Provider