This is an automated email from the ASF dual-hosted git repository.

xiaoyu 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 2d33f6b2e [ISSUE #3224] reuse HttpClient if available (#3225)
2d33f6b2e is described below

commit 2d33f6b2e67a417e2de3e5c90a5b5986cdd93d9b
Author: dragon-zhang <[email protected]>
AuthorDate: Wed Apr 13 19:30:35 2022 +0800

    [ISSUE #3224] reuse HttpClient if available (#3225)
    
    * [ISSUE #3224] reuse HttpClient if available
    
    * fix javadoc
---
 shenyu-plugin/shenyu-plugin-websocket/pom.xml          |  4 ++++
 .../plugin/websocket/WebSocketPluginConfiguration.java | 18 +++++++++++-------
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/shenyu-plugin/shenyu-plugin-websocket/pom.xml 
b/shenyu-plugin/shenyu-plugin-websocket/pom.xml
index e465cccf1..e28794e36 100644
--- a/shenyu-plugin/shenyu-plugin-websocket/pom.xml
+++ b/shenyu-plugin/shenyu-plugin-websocket/pom.xml
@@ -36,6 +36,10 @@
             <artifactId>shenyu-loadbalancer</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>io.projectreactor.netty</groupId>
+            <artifactId>reactor-netty</artifactId>
+        </dependency>
         <dependency>
             <groupId>io.projectreactor</groupId>
             <artifactId>reactor-test</artifactId>
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 3e116c19f..bf7877027 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
@@ -23,6 +23,7 @@ import 
org.apache.shenyu.plugin.base.handler.PluginDataHandler;
 import org.apache.shenyu.plugin.websocket.WebSocketPlugin;
 import 
org.apache.shenyu.plugin.websocket.context.WebSocketShenyuContextDecorator;
 import org.apache.shenyu.plugin.websocket.handler.WebSocketPluginDataHandler;
+import org.springframework.beans.factory.ObjectProvider;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
@@ -30,6 +31,7 @@ import 
org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClien
 import org.springframework.web.reactive.socket.client.WebSocketClient;
 import org.springframework.web.reactive.socket.server.WebSocketService;
 import 
org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService;
+import reactor.netty.http.client.HttpClient;
 
 /**
  * The type Web socket plugin configuration.
@@ -37,7 +39,7 @@ import 
org.springframework.web.reactive.socket.server.support.HandshakeWebSocket
 @Configuration
 @ConditionalOnProperty(value = {"shenyu.plugins.websocket.enabled"}, 
havingValue = "true", matchIfMissing = true)
 public class WebSocketPluginConfiguration {
-    
+
     /**
      * Websocket plugin data handler plugin data handler.
      *
@@ -47,7 +49,7 @@ public class WebSocketPluginConfiguration {
     public PluginDataHandler websocketPluginDataHandler() {
         return new WebSocketPluginDataHandler();
     }
-    
+
     /**
      * Web socket plugin web socket plugin.
      *
@@ -59,20 +61,22 @@ public class WebSocketPluginConfiguration {
     public WebSocketPlugin webSocketPlugin(final WebSocketClient 
webSocketClient, final WebSocketService webSocketService) {
         return new WebSocketPlugin(webSocketClient, webSocketService);
     }
-    
+
     /**
      * Reactor netty web socket client reactor netty web socket client.
      *
      * @param shenyuConfig the shenyu config
+     * @param httpClient   the http client
      * @return the reactor netty web socket client
      */
     @Bean
-    public ReactorNettyWebSocketClient reactorNettyWebSocketClient(final 
ShenyuConfig shenyuConfig) {
-        final ReactorNettyWebSocketClient webSocketClient = new 
ReactorNettyWebSocketClient();
+    public ReactorNettyWebSocketClient reactorNettyWebSocketClient(final 
ShenyuConfig shenyuConfig,
+                                                                   final 
ObjectProvider<HttpClient> httpClient) {
+        final ReactorNettyWebSocketClient webSocketClient = new 
ReactorNettyWebSocketClient(httpClient.getIfAvailable(HttpClient::create));
         
webSocketClient.setMaxFramePayloadLength(shenyuConfig.getWebsocket().getMaxFramePayloadSize()
 * 1024 * 1024);
         return webSocketClient;
     }
-    
+
     /**
      * Web socket service web socket service.
      *
@@ -82,7 +86,7 @@ public class WebSocketPluginConfiguration {
     public WebSocketService webSocketService() {
         return new HandshakeWebSocketService();
     }
-    
+
     /**
      * Web socket shenyu context decorator shenyu context decorator.
      *

Reply via email to