You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by zh...@apache.org on 2022/06/17 03:24:32 UTC
[incubator-shenyu] branch master updated: [ISSUE #3484] Fix sofa and websocket client lossless registration. (#3541)
This is an automated email from the ASF dual-hosted git repository.
zhangzicheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new bc67e69e8 [ISSUE #3484] Fix sofa and websocket client lossless registration. (#3541)
bc67e69e8 is described below
commit bc67e69e8ec8aec67b0e8fdf9e21c5a6243116eb
Author: 拉姆徐 <la...@gmail.com>
AuthorDate: Fri Jun 17 11:24:26 2022 +0800
[ISSUE #3484] Fix sofa and websocket client lossless registration. (#3541)
* [ISSUE #3484] fix sofa and websocket client lossless registration
* [ISSUE #3484] modify the scope of annotation ShenyuSpringWebSocketClient
---
...rocessor.java => SofaServiceEventListener.java} | 42 ++++++++++------------
.../annotation/ShenyuSpringWebSocketClient.java | 2 +-
...ava => SpringWebSocketClientEventListener.java} | 38 ++++++++++----------
.../pom.xml | 20 ++---------
.../examples/websocket/handler/EchoHandler.java | 2 --
.../client/sofa/ShenyuSofaClientConfiguration.java | 12 +++----
.../sofa/ShenyuSofaClientConfigurationTest.java | 26 +++++++-------
.../ShenyuSpringWebSocketClientConfiguration.java | 10 +++---
...enyuSpringWebSocketClientConfigurationTest.java | 8 ++---
9 files changed, 69 insertions(+), 91 deletions(-)
diff --git a/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceBeanPostProcessor.java b/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceEventListener.java
similarity index 88%
rename from shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceBeanPostProcessor.java
rename to shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceEventListener.java
index 605b4cc94..0a7bf7aa4 100644
--- a/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceBeanPostProcessor.java
+++ b/shenyu-client/shenyu-client-sofa/src/main/java/org/apache/shenyu/client/sofa/SofaServiceEventListener.java
@@ -19,16 +19,6 @@ package org.apache.shenyu.client.sofa;
import com.alipay.sofa.runtime.service.component.Service;
import com.alipay.sofa.runtime.spring.factory.ServiceFactoryBean;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.util.Arrays;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.client.core.constant.ShenyuClientConstants;
import org.apache.shenyu.client.core.disruptor.ShenyuClientRegisterEventPublisher;
@@ -44,18 +34,27 @@ import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.support.AopUtils;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.lang.NonNull;
import org.springframework.util.ReflectionUtils;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.stream.Collectors;
+
/**
- * The Sofa ServiceBean PostProcessor.
+ * The Sofa Service Event Listener.
*/
-public class SofaServiceBeanPostProcessor implements BeanPostProcessor {
+public class SofaServiceEventListener implements ApplicationListener<ContextRefreshedEvent> {
- private static final Logger LOG = LoggerFactory.getLogger(SofaServiceBeanPostProcessor.class);
+ private static final Logger LOG = LoggerFactory.getLogger(SofaServiceEventListener.class);
/**
* api path separator.
@@ -64,8 +63,6 @@ public class SofaServiceBeanPostProcessor implements BeanPostProcessor {
private final ShenyuClientRegisterEventPublisher publisher = ShenyuClientRegisterEventPublisher.getInstance();
- private final ExecutorService executorService;
-
private final String contextPath;
private final String appName;
@@ -74,7 +71,7 @@ public class SofaServiceBeanPostProcessor implements BeanPostProcessor {
private final String port;
- public SofaServiceBeanPostProcessor(final PropertiesConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
+ public SofaServiceEventListener(final PropertiesConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
Properties props = clientConfig.getProps();
String contextPath = props.getProperty(ShenyuClientConstants.CONTEXT_PATH);
String appName = props.getProperty(ShenyuClientConstants.APP_NAME);
@@ -85,16 +82,15 @@ public class SofaServiceBeanPostProcessor implements BeanPostProcessor {
this.appName = appName;
this.host = props.getProperty(ShenyuClientConstants.HOST);
this.port = props.getProperty(ShenyuClientConstants.PORT);
- executorService = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("shenyu-sofa-client-thread-pool-%d").build());
publisher.start(shenyuClientRegisterRepository);
}
@Override
- public Object postProcessAfterInitialization(@NonNull final Object bean, final String beanName) throws BeansException {
- if (bean instanceof ServiceFactoryBean) {
- executorService.execute(() -> handler((ServiceFactoryBean) bean));
+ public void onApplicationEvent(final ContextRefreshedEvent contextRefreshedEvent) {
+ Map<String, ServiceFactoryBean> serviceBean = contextRefreshedEvent.getApplicationContext().getBeansOfType(ServiceFactoryBean.class);
+ for (Map.Entry<String, ServiceFactoryBean> entry : serviceBean.entrySet()) {
+ handler(entry.getValue());
}
- return bean;
}
private void handler(final ServiceFactoryBean serviceBean) {
diff --git a/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/annotation/ShenyuSpringWebSocketClient.java b/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/annotation/ShenyuSpringWebSocketClient.java
index 148ba199d..3914df2b4 100644
--- a/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/annotation/ShenyuSpringWebSocketClient.java
+++ b/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/annotation/ShenyuSpringWebSocketClient.java
@@ -28,7 +28,7 @@ import java.lang.annotation.Target;
* The interface shenyu client.
*/
@Retention(RetentionPolicy.RUNTIME)
-@Target({ElementType.TYPE, ElementType.METHOD})
+@Target(ElementType.TYPE)
public @interface ShenyuSpringWebSocketClient {
/**
diff --git a/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientBeanPostProcessor.java b/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListener.java
similarity index 88%
rename from shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientBeanPostProcessor.java
rename to shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListener.java
index 86aba860a..a182dc135 100644
--- a/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientBeanPostProcessor.java
+++ b/shenyu-client/shenyu-client-websocket/shenyu-client-spring-websocket/src/main/java/org/apache/shenyu/client/spring/websocket/init/SpringWebSocketClientEventListener.java
@@ -30,8 +30,8 @@ import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.support.AopUtils;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.config.BeanPostProcessor;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.lang.NonNull;
@@ -42,20 +42,21 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Objects;
import java.util.Properties;
/**
- * The type Shenyu websocket client bean post processor.
+ * The type Shenyu websocket client event listener.
*/
-public class SpringWebSocketClientBeanPostProcessor implements BeanPostProcessor {
+public class SpringWebSocketClientEventListener implements ApplicationListener<ContextRefreshedEvent> {
/**
* api path separator.
*/
private static final String PATH_SEPARATOR = "/";
- private static final Logger LOG = LoggerFactory.getLogger(SpringWebSocketClientBeanPostProcessor.class);
+ private static final Logger LOG = LoggerFactory.getLogger(SpringWebSocketClientEventListener.class);
private final ShenyuClientRegisterEventPublisher publisher = ShenyuClientRegisterEventPublisher.getInstance();
@@ -70,13 +71,13 @@ public class SpringWebSocketClientBeanPostProcessor implements BeanPostProcessor
private final String[] pathAttributeNames = new String[] {"path", "value"};
/**
- * Instantiates a new Spring websocket client bean post processor.
+ * Instantiates a new Spring websocket client event listener.
*
* @param clientConfig the client config
* @param shenyuClientRegisterRepository the shenyu client register repository
*/
- public SpringWebSocketClientBeanPostProcessor(final PropertiesConfig clientConfig,
- final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
+ public SpringWebSocketClientEventListener(final PropertiesConfig clientConfig,
+ final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
Properties props = clientConfig.getProps();
this.appName = props.getProperty(ShenyuClientConstants.APP_NAME);
@@ -93,9 +94,14 @@ public class SpringWebSocketClientBeanPostProcessor implements BeanPostProcessor
}
@Override
- public Object postProcessAfterInitialization(@NonNull final Object bean,
- @NonNull final String beanName) throws BeansException {
+ public void onApplicationEvent(final ContextRefreshedEvent contextRefreshedEvent) {
+ Map<String, Object> beans = contextRefreshedEvent.getApplicationContext().getBeansWithAnnotation(ShenyuSpringWebSocketClient.class);
+ for (Map.Entry<String, Object> entry : beans.entrySet()) {
+ handler(entry.getValue());
+ }
+ }
+ private void handler(final Object bean) {
Class<?> clazz;
clazz = bean.getClass();
if (AopUtils.isAopProxy(bean)) {
@@ -104,14 +110,14 @@ public class SpringWebSocketClientBeanPostProcessor implements BeanPostProcessor
final String superPath = buildApiSuperPath(clazz);
// Filter out is not controller out
- if (Boolean.TRUE.equals(isFull) || !hasAnnotation(clazz, ShenyuSpringWebSocketClient.class)) {
- return bean;
+ if (Boolean.TRUE.equals(isFull)) {
+ return;
}
final ShenyuSpringWebSocketClient beanShenyuClient = AnnotatedElementUtils.findMergedAnnotation(clazz, ShenyuSpringWebSocketClient.class);
// Compatible with previous versions
if (Objects.nonNull(beanShenyuClient) && superPath.contains("*")) {
publisher.publishEvent(buildMetaDataDTO(beanShenyuClient, pathJoin(contextPath, superPath)));
- return bean;
+ return;
}
final Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(clazz);
for (Method method : methods) {
@@ -121,12 +127,6 @@ public class SpringWebSocketClientBeanPostProcessor implements BeanPostProcessor
publisher.publishEvent(buildMetaDataDTO(webSocketClient, buildApiPath(method, superPath)));
}
}
- return bean;
- }
-
- private <A extends Annotation> boolean hasAnnotation(final @NonNull Class<?> clazz,
- final @NonNull Class<A> annotationType) {
- return Objects.nonNull(AnnotatedElementUtils.findMergedAnnotation(clazz, annotationType));
}
private String buildApiPath(@NonNull final Method method, @NonNull final String superPath) {
diff --git a/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-reactive-websocket/pom.xml b/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-reactive-websocket/pom.xml
index cfd12cee7..fbdbaa837 100644
--- a/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-reactive-websocket/pom.xml
+++ b/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-reactive-websocket/pom.xml
@@ -62,24 +62,8 @@
</dependency>
<dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- <!-- <version>2.1.6.RELEASE</version>-->
- <exclusions>
- <exclusion>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-logging</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-websocket</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-websocket</artifactId>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-all</artifactId>
</dependency>
</dependencies>
diff --git a/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-reactive-websocket/src/main/java/org/apache/shenyu/examples/websocket/handler/EchoHandler.java b/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-reactive-websocket/src/main/java/org/apache/shenyu/examples/websocket/handler/EchoHandler.java
index c03cd69f5..a9dd557bb 100644
--- a/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-reactive-websocket/src/main/java/org/apache/shenyu/examples/websocket/handler/EchoHandler.java
+++ b/shenyu-examples/shenyu-examples-websocket/shenyu-example-spring-reactive-websocket/src/main/java/org/apache/shenyu/examples/websocket/handler/EchoHandler.java
@@ -17,7 +17,6 @@
package org.apache.shenyu.examples.websocket.handler;
-import org.apache.shenyu.client.spring.websocket.annotation.ShenyuSpringWebSocketClient;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.socket.WebSocketHandler;
@@ -32,7 +31,6 @@ public class EchoHandler implements WebSocketHandler {
@Override
@NonNull
- @ShenyuSpringWebSocketClient("/org/apache/shenyu/examples/websocket/**")
public Mono<Void> handle(final WebSocketSession session) {
return session.send(
session.receive()
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-sofa/src/main/java/org/apache/shenyu/springboot/starter/client/sofa/ShenyuSofaClientConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-sofa/src/main/java/org/apache/shenyu/springboot/starter/client/sofa/ShenyuSofaClientConfiguration.java
index a4831bccd..0269bcd41 100644
--- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-sofa/src/main/java/org/apache/shenyu/springboot/starter/client/sofa/ShenyuSofaClientConfiguration.java
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-sofa/src/main/java/org/apache/shenyu/springboot/starter/client/sofa/ShenyuSofaClientConfiguration.java
@@ -18,7 +18,7 @@
package org.apache.shenyu.springboot.starter.client.sofa;
-import org.apache.shenyu.client.sofa.SofaServiceBeanPostProcessor;
+import org.apache.shenyu.client.sofa.SofaServiceEventListener;
import org.apache.shenyu.common.enums.RpcTypeEnum;
import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
import org.apache.shenyu.register.common.config.ShenyuClientConfig;
@@ -28,21 +28,21 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
- * Sofa type client bean postprocessor.
+ * Sofa type client event listener.
*/
@Configuration
@ImportAutoConfiguration(ShenyuClientCommonBeanConfiguration.class)
public class ShenyuSofaClientConfiguration {
/**
- * Sofa service bean post processor.
+ * Sofa service event listener.
*
* @param clientConfig the client config
* @param shenyuClientRegisterRepository the shenyuClientRegisterRepository
- * @return the sofa service bean post processor
+ * @return the sofa service event listener
*/
@Bean
- public SofaServiceBeanPostProcessor sofaServiceBeanPostProcessor(final ShenyuClientConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
- return new SofaServiceBeanPostProcessor(clientConfig.getClient().get(RpcTypeEnum.SOFA.getName()), shenyuClientRegisterRepository);
+ public SofaServiceEventListener sofaServiceEventListener(final ShenyuClientConfig clientConfig, final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
+ return new SofaServiceEventListener(clientConfig.getClient().get(RpcTypeEnum.SOFA.getName()), shenyuClientRegisterRepository);
}
}
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-sofa/src/test/java/org/apache/shenyu/springboot/starter/client/sofa/ShenyuSofaClientConfigurationTest.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-sofa/src/test/java/org/apache/shenyu/springboot/starter/client/sofa/ShenyuSofaClientConfigurationTest.java
index 8fcc0416d..c10577106 100644
--- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-sofa/src/test/java/org/apache/shenyu/springboot/starter/client/sofa/ShenyuSofaClientConfigurationTest.java
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-sofa/src/test/java/org/apache/shenyu/springboot/starter/client/sofa/ShenyuSofaClientConfigurationTest.java
@@ -18,7 +18,7 @@
package org.apache.shenyu.springboot.starter.client.sofa;
-import org.apache.shenyu.client.sofa.SofaServiceBeanPostProcessor;
+import org.apache.shenyu.client.sofa.SofaServiceEventListener;
import org.apache.shenyu.register.client.http.utils.RegisterUtils;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;
@@ -41,26 +41,26 @@ import static org.mockito.Mockito.mockStatic;
public class ShenyuSofaClientConfigurationTest {
@Test
- public void testSofaServiceBeanPostProcessor() {
+ public void testSofaServiceEventListener() {
MockedStatic<RegisterUtils> registerUtilsMockedStatic = mockStatic(RegisterUtils.class);
registerUtilsMockedStatic.when(() -> RegisterUtils.doLogin(any(), any(), any())).thenReturn(Optional.ofNullable("token"));
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(ShenyuSofaClientConfiguration.class))
.withBean(ShenyuSofaClientConfigurationTest.class)
.withPropertyValues(
- "debug=true",
- "shenyu.register.registerType=http",
- "shenyu.register.serverLists=http://localhost:9095",
- "shenyu.register.props.username=admin",
- "shenyu.register.props.password=123456",
- "shenyu.client.sofa.props[contextPath]=/sofa",
- "shenyu.client.sofa.props[appName]=sofa",
- "shenyu.client.sofa.props[host]=127.0.0.1",
- "shenyu.client.sofa.props[port]=8888"
+ "debug=true",
+ "shenyu.register.registerType=http",
+ "shenyu.register.serverLists=http://localhost:9095",
+ "shenyu.register.props.username=admin",
+ "shenyu.register.props.password=123456",
+ "shenyu.client.sofa.props[contextPath]=/sofa",
+ "shenyu.client.sofa.props[appName]=sofa",
+ "shenyu.client.sofa.props[host]=127.0.0.1",
+ "shenyu.client.sofa.props[port]=8888"
)
.run(context -> {
- SofaServiceBeanPostProcessor processor = context.getBean("sofaServiceBeanPostProcessor", SofaServiceBeanPostProcessor.class);
- assertNotNull(processor);
+ SofaServiceEventListener eventListener = context.getBean("sofaServiceEventListener", SofaServiceEventListener.class);
+ assertNotNull(eventListener);
}
);
registerUtilsMockedStatic.close();
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/main/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketClientConfiguration.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/main/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketClientConfiguration.java
index 45e9b3089..c7c178c45 100644
--- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/main/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketClientConfiguration.java
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/main/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketClientConfiguration.java
@@ -18,7 +18,7 @@
package org.apache.shenyu.springboot.starter.client.spring.websocket;
import org.apache.shenyu.client.spring.websocket.init.SpringContextRegisterListener;
-import org.apache.shenyu.client.spring.websocket.init.SpringWebSocketClientBeanPostProcessor;
+import org.apache.shenyu.client.spring.websocket.init.SpringWebSocketClientEventListener;
import org.apache.shenyu.common.enums.RpcTypeEnum;
import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
import org.apache.shenyu.register.common.config.ShenyuClientConfig;
@@ -35,17 +35,17 @@ import org.springframework.context.annotation.Configuration;
public class ShenyuSpringWebSocketClientConfiguration {
/**
- * Spring web socket client bean post processor.
+ * Spring web socket client event listener.
*
* @param clientConfig the client config
* @param shenyuClientRegisterRepository the shenyu client register repository
- * @return the spring web socket client bean post processor
+ * @return the spring web socket client event listener
*/
@Bean
- public SpringWebSocketClientBeanPostProcessor springWebSocketClientBeanPostProcessor(
+ public SpringWebSocketClientEventListener springWebSocketClientEventListener(
final ShenyuClientConfig clientConfig,
final ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
- return new SpringWebSocketClientBeanPostProcessor(clientConfig.getClient().get(RpcTypeEnum.WEB_SOCKET.getName()), shenyuClientRegisterRepository);
+ return new SpringWebSocketClientEventListener(clientConfig.getClient().get(RpcTypeEnum.WEB_SOCKET.getName()), shenyuClientRegisterRepository);
}
/**
diff --git a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/test/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketClientConfigurationTest.java b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/test/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketClientConfigurationTest.java
index 8efb3f426..5ebfe2bcc 100644
--- a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/test/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketClientConfigurationTest.java
+++ b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/test/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketClientConfigurationTest.java
@@ -19,7 +19,7 @@ package org.apache.shenyu.springboot.starter.client.spring.websocket;
import java.util.Optional;
import org.apache.shenyu.client.spring.websocket.init.SpringContextRegisterListener;
-import org.apache.shenyu.client.spring.websocket.init.SpringWebSocketClientBeanPostProcessor;
+import org.apache.shenyu.client.spring.websocket.init.SpringWebSocketClientEventListener;
import org.apache.shenyu.register.client.http.utils.RegisterUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -60,12 +60,12 @@ public class ShenyuSpringWebSocketClientConfigurationTest {
}
@Test
- public void testSpringWebSocketClientBeanPostProcessor() {
+ public void testSpringWebSocketClientEventListener() {
MockedStatic<RegisterUtils> registerUtilsMockedStatic = mockStatic(RegisterUtils.class);
registerUtilsMockedStatic.when(() -> RegisterUtils.doLogin(any(), any(), any())).thenReturn(Optional.ofNullable("token"));
applicationContextRunner.run(context -> {
- SpringWebSocketClientBeanPostProcessor processor = context.getBean("springWebSocketClientBeanPostProcessor", SpringWebSocketClientBeanPostProcessor.class);
- assertNotNull(processor);
+ SpringWebSocketClientEventListener eventListener = context.getBean("springWebSocketClientEventListener", SpringWebSocketClientEventListener.class);
+ assertNotNull(eventListener);
});
registerUtilsMockedStatic.close();
}