Hoang
Hoang

Reputation: 857

Spring Cloud Gateway enable http2 don't receive the response of websocket destination service

I am using Spring Cloud Gateway to be service between client and destination service same as diagram below

diagram

When I disable http2, I call websocket to Spring cloud gateway, it connect and receive response. However when enable http2, it only connect but don't receive response.

url of spring cloud gateway: wss://localhost:9967/athena/v1/stream

url of destination service: wss://athenader.tcbs.com.vn/athena/v1/stream

This is example call from postman to Spring cloud gateway

postman call to spring cloud gateway

I also try show log debug but don't find any abnormal. I hope people can determine issue to me to resolve it.

This is structure source code in project

structure source code

Content of file source code

1. 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.12</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <url/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <scm>
        <connection/>
        <developerConnection/>
        <tag/>
        <url/>
    </scm>
    <properties>
        <java.version>17</java.version>
        <spring-cloud.version>2022.0.5</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

2. application.yaml

server:
  port: 9967
  http2:
    enabled: false
  ssl:
    key-store: classpath:keystore/key.keystore
    key-store-password: mypassword
    key-store-type: PKCS12
spring:
  application:
    name: gateway
  cloud:
    gateway:
      routes:
        - id: websocket_route
          uri: wss://athenader.tcbs.com.vn
          predicates:
            - Path=/athena/v1/stream
logging:
  level:
    io:
      netty: TRACE
    reactor:
      netty: TRACE
    org:
      springframework:
        web:
          reactive:
            socket: TRACE
        cloud:
          gateway: TRACE
        reactive:
          socket: TRACE

3. key.keystore

4. Main

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

Upvotes: 0

Views: 103

Answers (0)

Related Questions