【问题标题】:how to route spring cloud gateway to websocket service?如何将spring cloud gateway路由到websocket服务?
【发布时间】:2019-10-12 13:57:26
【问题描述】:

我想在 spring 云网关上路由我的 websocket 服务

作为 Spring Cloud Gateway 文档,我尝试这样做并且它有效:

spring:
  cloud:
    gateway:
      routes:
      - id: websocket-sockjs-route
        uri: http://localhost:8085
        predicates:
        - Path=/websocket/info/**
      - id: websocket_route
        uri: ws://localhost:8085
        predicates:
        - Path=/websocket/**

但是当我尝试这个时,它不会工作:

spring:
  cloud:
    gateway:
      routes:
      - id: websocket-sockjs-route
        uri: http://websocket-service:8085
        predicates:
        - Path=/websocket/info/**
      - id: websocket_route
        uri: ws://websocket-service:8085
        predicates:
        - Path=/websocket/**

我想让我的 websocket 路由变成这样:

spring:
  cloud:
    gateway:
      routes:
      - id: hello-world-route
        uri: lb://hello-world:8081
        predicates:
        - Path=/hello

【问题讨论】:

    标签: spring-boot websocket spring-cloud-gateway


    【解决方案1】:

    你可以看看这个问题:gateway

    它应该通过这种方式工作:

    spring:
      cloud:
        gateway:
          routes:
          - id: websocket-sockjs-route
            uri: http://websocket-service
            predicates:
            - Path=/websocket/info/**
          - id: websocket_route
            uri: lb:ws://websocket-service
            predicates:
            - Path=/websocket/**
    

    如果您使用发现客户端,则无需设置端口,只需使用服务名称即可。

    【讨论】:

    • 那么标题呢?因为当我调用 websocket/info 时……我得到了 httpcode 400,我认为这可能是因为缺少正确的标头属性……你怎么看?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-02
    • 2019-08-03
    • 2019-03-31
    • 2020-08-02
    • 2023-03-09
    • 2023-01-21
    • 1970-01-01
    相关资源
    最近更新 更多