遇到的问题
客户端程序退出时报如下错误
2023-02-26 09:18:08.342 [main-EventThread] ERROR o.apache.curator.framework.recipes.cache.NodeCache -
java.lang.IllegalStateException: Expected state [STARTED] was [STOPPED]
at org.apache.curator.shaded.com.google.common.base.Preconditions.checkState(Preconditions.java:823)
at org.apache.curator.framework.imps.CuratorFrameworkImpl.checkState(CuratorFrameworkImpl.java:423)
at org.apache.curator.framework.imps.CuratorFrameworkImpl.checkExists(CuratorFrameworkImpl.java:450)
at org.apache.curator.framework.recipes.cache.NodeCache.reset(NodeCache.java:261)
at org.apache.curator.framework.recipes.cache.NodeCache.access$100(NodeCache.java:60)
at org.apache.curator.framework.recipes.cache.NodeCache$2.process(NodeCache.java:104)
at org.apache.curator.framework.imps.NamespaceWatcher.process(NamespaceWatcher.java:77)
at org.apache.zookeeper.ClientCnxn$EventThread.processEvent(ClientCnxn.java:580)
at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:555)
业务简单描述
- SpringBoot + Dubbo3写的一个服务,Zookeeper为注册中心;
- Client端是定时任务,通过crontab进行调度;
- 目前Server端没有报错,Client端在程序退出时报以上错误;
- Client目前是启动执行完成业务后会退出,不会await,此时就会报上述错误;
- Client如果启动后执行完成业务后不退出,一直await,则不会报上述错误。
环境
名称 | 版本 |
---|---|
JDK | 17 |
SpringBoot | 2.7.9 |
Dubbo | 3.1.7 |
Client端相关代码
@Slf4j
@EnableDubbo
@SpringBootApplication
public class Application implements CommandLineRunner {
@Value("${spring.profiles.active}")
private String springProfile;
@DubboReference(
version = "${services.version}"
, url = "${services.url}")
private TestServices services;
public static void main(String[] args) {
ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
ApplicationModel.defaultModel().destroy();
//System.exit(SpringApplication.exit(ctx, () -> 0));
}
@Override
public void run(String... strings) {
log.info(">>>>>>{}<<<<<<", springProfile);
log.info("Result:{}", services.test());
}
}
Client端pom中依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.9</version>
<relativePath/>
</parent>
<properties>
<dubbo.version>3.1.7</dubbo.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
......
<dependencies>
<!-- .............................................. spring boot ...-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- .............................................. dubbo ...-->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper-curator5</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
<exclusions>
<exclusion>
<artifactId>slf4j-reload4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
yml配置
server:
shutdown: graceful
dubbo:
application:
name: test-consumer
registry:
id: test-consumer
address: zookeeper://192.168.1.100:2181
config-center:
address: zookeeper://192.168.1.100:2181
metadata-report:
address: zookeeper://192.168.1.100:2181
consumer:
timeout: 3000
check: false
retries: 0
services:
version: 1.0.0
url:
望赐教!