This is an automated email from the ASF dual-hosted git repository.
tydhot 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 edc8fdc [type: refactor] support websocket client configuration
(#3014)
edc8fdc is described below
commit edc8fdc06582c123e6cd01d0851b2cd62925aaad
Author: Qicz <[email protected]>
AuthorDate: Thu Mar 10 15:09:54 2022 +0800
[type: refactor] support websocket client configuration (#3014)
* [type: refactor] support websocket client max frame payload length
configuration.
* [type: refactor] support websocket client max frame payload length
configuration.
* [type: refactor] support websocket client max frame payload length
configuration.
* [type: refactor] support websocket client max frame payload length
configuration.
---
.../apache/shenyu/common/config/ShenyuConfig.java | 47 ++++++++++++++++++++++
.../websocket/WebSocketPluginConfiguration.java | 8 +++-
.../WebSocketPluginConfigurationTest.java | 3 ++
3 files changed, 56 insertions(+), 2 deletions(-)
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java
index 6f9cf13..1c1786e 100644
---
a/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java
+++
b/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java
@@ -53,6 +53,8 @@ public class ShenyuConfig {
private RibbonConfig ribbon = new RibbonConfig();
private Local local = new Local();
+
+ private WebsocketConfig websocket = new WebsocketConfig();
/**
* Gets the local config.
@@ -242,6 +244,24 @@ public class ShenyuConfig {
public CrossFilterConfig getCross() {
return cross;
}
+
+ /**
+ * Gets the websocket config.
+ *
+ * @return the websocket config
+ */
+ public WebsocketConfig getWebsocket() {
+ return websocket;
+ }
+
+ /**
+ * Sets the websocket config.
+ *
+ * @param websocket the websocket config
+ */
+ public void setWebsocket(final WebsocketConfig websocket) {
+ this.websocket = websocket;
+ }
/**
* Sets cross.
@@ -1123,4 +1143,31 @@ public class ShenyuConfig {
this.sha512Key = sha512Key;
}
}
+
+ /**
+ * the websocket config.
+ */
+ public static class WebsocketConfig {
+
+ /**
+ * max frame pay load size mb.
+ */
+ private Integer maxFramePayloadSize = 10;
+
+ /**
+ * Get max frame payload size.
+ * @return the max frame payload szie
+ */
+ public Integer getMaxFramePayloadSize() {
+ return maxFramePayloadSize;
+ }
+
+ /**
+ * Set max frame payload size.
+ * @param maxFramePayloadSize the max frame paylod size
+ */
+ public void setMaxFramePayloadSize(final Integer maxFramePayloadSize) {
+ this.maxFramePayloadSize = maxFramePayloadSize;
+ }
+ }
}
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/main/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfiguration.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/main/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfiguration.java
index 90d2cbf..6efc3cb 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/main/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfiguration.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/main/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfiguration.java
@@ -17,6 +17,7 @@
package org.apache.shenyu.springboot.plugin.websocket;
+import org.apache.shenyu.common.config.ShenyuConfig;
import org.apache.shenyu.plugin.api.context.ShenyuContextDecorator;
import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
import org.apache.shenyu.plugin.websocket.WebSocketPlugin;
@@ -60,11 +61,14 @@ public class WebSocketPluginConfiguration {
/**
* Reactor netty web socket client reactor netty web socket client.
*
+ * @param shenyuConfig the shenyu config
* @return the reactor netty web socket client
*/
@Bean
- public ReactorNettyWebSocketClient reactorNettyWebSocketClient() {
- return new ReactorNettyWebSocketClient();
+ public ReactorNettyWebSocketClient reactorNettyWebSocketClient(final
ShenyuConfig shenyuConfig) {
+ final ReactorNettyWebSocketClient webSocketClient = new
ReactorNettyWebSocketClient();
+
webSocketClient.setMaxFramePayloadLength(shenyuConfig.getWebsocket().getMaxFramePayloadSize()
* 1024 * 1024);
+ return webSocketClient;
}
/**
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/test/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfigurationTest.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/test/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfigurationTest.java
index 234dc9c..810f75c 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/test/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfigurationTest.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-websocket/src/test/java/org/apache/shenyu/springboot/plugin/websocket/WebSocketPluginConfigurationTest.java
@@ -17,6 +17,7 @@
package org.apache.shenyu.springboot.plugin.websocket;
+import org.apache.shenyu.common.config.ShenyuConfig;
import org.apache.shenyu.common.enums.PluginEnum;
import org.apache.shenyu.plugin.api.context.ShenyuContextDecorator;
import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
@@ -47,6 +48,8 @@ public class WebSocketPluginConfigurationTest {
applicationContextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(WebSocketPluginConfiguration.class))
.withBean(WebSocketPluginConfigurationTest.class)
+ .withConfiguration(AutoConfigurations.of(ShenyuConfig.class))
+ .withBean(ShenyuConfig.class)
.withPropertyValues("debug=true");
}