我们有许多 Spring Boot 应用程序向 Consul 注册(通过 Spring Cloud Consul)。如果我通过以下方式停止这些应用程序,docker-compose stop myservice
那么它们会正确注销自己并从 Consul 中消失。
如果我使用,docker-compose kill myservice
则不会发生注销。我知道在 UNIX 系统上不可能捕获 SIGKILL 事件,因此无法强制取消注册。
因此,我们看到的是 Consul 中从未删除的服务(标记为critical
但在 UI 中仍然可见)。有没有办法强制 Consul 刷新注册的内容,以便删除死服务?
谢谢
缺口
我正在使用新版本的 Ubuntu、Consul 和 Spring Boot 升级环境。乍一看,一切似乎都运行良好。该应用程序连接到 Consul,请求其配置并启动。然而,几分钟后,出现了一些中断,此消息大约每 2 秒重复一次:
com.ecwid.consul.transport.TransportException: javax.net.ssl.SSLHandshakeException: Remote host terminated the handshake
at com.ecwid.consul.transport.AbstractHttpTransport.executeRequest(AbstractHttpTransport.java:77)
at com.ecwid.consul.transport.AbstractHttpTransport.makeGetRequest(AbstractHttpTransport.java:34)
at com.ecwid.consul.v1.ConsulRawClient.makeGetRequest(ConsulRawClient.java:128)
at com.ecwid.consul.v1.catalog.CatalogConsulClient.getCatalogServices(CatalogConsulClient.java:120)
at com.ecwid.consul.v1.ConsulClient.getCatalogServices(ConsulClient.java:372)
at org.springframework.cloud.consul.discovery.ConsulCatalogWatch.catalogServicesWatch(ConsulCatalogWatch.java:129)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: javax.net.ssl.SSLHandshakeException: Remote host terminated the handshake
at java.base/sun.security.ssl.SSLSocketImpl.handleEOF(SSLSocketImpl.java:1313)
at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1152)
at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1055)
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:395)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380)
Run Code Online (Sandbox Code Playgroud)
我追踪了消息每 2 秒出现一次到应用程序运行状况检查的事实。一旦错误第一次发生,它会在每次后续的健康检查中继续发生。这是通过关闭健康检查并重新启动来确认的。当达到 Consul-data 上的 TTL 时,这导致错误仅发生一次。
我对问题的理解到此结束。我试图将其追溯到几件事,但这些都没有找到解决方案:
我有一个监控应用程序,其中正在运行固定速率任务。这是拉入用 Consul 配置的配置参数。我想引入更新的配置,所以我添加了@RefreshScope。但是,一旦我更新 Consul 上的配置值,fixedRate 任务就会停止运行。
@Service
@RefreshScope
public class MonitorService {
@Autowired
private AppConfig appConfig;
@PostConstruct
public void postConstRun() {
System.out.println(appConfig.getMonitorConfig());
}
@Scheduled(fixedRate = 1000)
public void scheduledMonitorScan() {
System.out.println("MonitorConfig:" + appConfig.getMonitorConfig());
}
}
Run Code Online (Sandbox Code Playgroud)
AppConfig 类只有一个 String 参数:
@Configuration
@Getter
@Setter
public class AppConfig {
@Value("${monitor-config:default value}")
private String monitorConfig;
}
Run Code Online (Sandbox Code Playgroud)
一旦我更新领事中的值,计划任务就会停止运行(在 sheduledMonitorScan 方法中显示)并停止显示。
我正在实现一个服务发现,并评估两个选项:Eureka 和 Consul。
帮我决定吧!我倾向于尤里卡,但我需要解决一个主要的技术问题。我的基础设施基于 openshift。我可以让多个容器在负载均衡器后面运行 Eureka 服务器。据我所知,每个服务器都需要相互通信。另外,Eureka主要与AWS一起使用......
(新手)问题:
1)如何配置每个Eureka Server相互通信?我有一个(负载平衡)URL。我担心每个服务器可能会变得不同步。
2)我错过了什么吗?
consul netflix-eureka spring-cloud-netflix spring-cloud-consul
我对这个配置有点困惑。我的 Spring Boot 应用程序@EnableDiscoveryClient
已spring.cloud.consul.host
设置为localhost
. 我正在运行我的引导应用程序的主机上运行 Consul 代理,但我有几个问题(似乎无法在文档中找到我的答案)。
这个配置可以接受多个值吗?
@EnableDiscoveryClient
?(这也感觉不对;一方面,即使一个代理应该能够告诉集群的所有信息,这似乎也是一个单点故障;如果我无法联系到这个代理怎么办?)我有一个Spring Boot应用程序,我想获得领事代理上的属性。
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages={"com.commons"})
public class MainAppProxy implements CommandLineRunner {
@Value("${proxy.endpoint}")
private String endpointAddress;
Run Code Online (Sandbox Code Playgroud)
我的application.properties在src / main / resources下
spring.application.name=SOAPProxy
spring.cloud.consul.host=http://10.0.1.241
spring.cloud.consul.port=8500
spring.cloud.config.discovery.enabled=false
Run Code Online (Sandbox Code Playgroud)
在pom.xml中,我具有以下配置(简短版本)
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR5</version>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
Run Code Online (Sandbox Code Playgroud)
这些属性以以下格式存储在领事上:Business / SOAPProxy / proxy.endpoint
当应用程序启动时,它似乎找到了consul,但是在尝试使用consul @Value(“ $ {proxy.endpoint}”)之前无法获取值,如何获取consul的属性?
我正在创建一个Spring Boot
应用程序,它将读取类似DB属性的配置Consul
.但是我无法使用我的应用程序从Consul读取键值.以下是我要做的事情.
**pom.xml**
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>com.tuturself</groupId>
<artifactId>spring-boot-consul</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/>
</parent>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.retry.version>1.2.1.RELEASE</spring.retry.version>
<consul.version>1.1.2.RELEASE</consul.version>
<consul.discovery.version>1.1.2.RELEASE</consul.discovery.version>
<jackson.version>2.8.1</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-all</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-consul-discovery</artifactId>
<version>${consul.discovery.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
<version>${spring.retry.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
</dependencies>
<build> …
Run Code Online (Sandbox Code Playgroud) spring-boot consul microservices spring-cloud spring-cloud-consul
我正在使用Discovery的第一个bootstrap功能和Consul作为Discovery Server,Config Server的URL位于启动期间,我能够获得application.properties
.我还需要logback-spring.xml
从Config服务器获取配置,我不知道如何.
我应该在logging.config={???}logback-spring.xml
属性中指定什么不将URL硬编码到Config Server?
在Consul集成之前,我使用根据Serving Plain文本文档形成的url和属性中的硬编码配置服务器URL,它工作正常,但现在我们想避免这种情况.
从我调试的内容来看,在重新初始化日志系统期间没有使用Discovery客户端PropertySourceBootstrapConfiguration
.
logback spring-boot spring-cloud-config spring-cloud-consul spring-logback
我启用了 /health 端点,但我只是不希望它在同一台机器上列出 Consul 监控的所有服务。
这是我的 application.properties:
# Enable just the health endpoint.
endpoints.health.enabled=true
# Disable all default endpoints and Spring Cloud endpoints.
endpoints.enabled=false
endpoints.consul.enabled=false
endpoints.pause.enabled=false
endpoints.resume.enabled=false
endpoints.refresh.enabled=false
endpoints.restart.enabled=false
endpoints.shutdown.enabled=false
endpoints.env.enabled=false
management.health.db.enabled=false
management.health.diskspace.enabled=false
management.health.defaults.enabled=false
Run Code Online (Sandbox Code Playgroud)
...这就是 /health 当前发出的信息:
$ curl -o- http://localhost:8080/health | python -m json.tool
{
"consul": {
"advertiseAddress": "10.10.10.10",
"bindAddress": "10.10.10.10",
"clientAddress": "127.0.0.1",
"datacenter": "DC",
"domain": "consul.",
"nodeName": "mynode",
"services": {
"myservice1": [
"tag1"
],
"myservice2": [
"tag1",
"tag2"
]
},
"status": "UP"
},
"description": "Spring Cloud Consul Discovery …
Run Code Online (Sandbox Code Playgroud) spring-boot spring-cloud spring-boot-actuator spring-cloud-consul
我试图将我的注册服务器从"Eureka"更改为"Consul",并将Consul更改为我的配置服务器.使用Consul进行服务发现是成功的.但我无法理解如何获取键/值对选项来引导我的应用程序.我有可能做到这一点吗?
我使用具有以下依赖性的弹簧靴
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
这是我的春季启动应用程序ConsuleDemoApplication.class
@EnableDiscoveryClient
@SpringBootApplication
@RestController
public class ConsuleDemoApplication {
@RequestMapping("/")
public String home() {
return "Hello world";
}
public static void main(String[] args) {
SpringApplication.run(ConsuleDemoApplication.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
和我的bootstrap.yml是
spring:
cloud:
consul:
discovery:
healthCheckInterval: 15s
instanceId: ${spring.application.name}:${spring.application.instance_id:${random.value}}
application:
name: consul_demo
Run Code Online (Sandbox Code Playgroud) configuration spring-boot consul microservices spring-cloud-consul