如何将 spring 云网关路由到 websocket 服务? [英] how to route spring cloud gateway to websocket service?
本文介绍了如何将 spring 云网关路由到 websocket 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 spring 云网关上路由我的 websocket 服务
I want to route my websocket-service on spring cloud gateway
作为 spring 云网关文档,我尝试这样做并且它有效:
as spring cloud gateway docs, I tried to do this and it works :
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/**
但是当我尝试这个时,它不起作用:
but when i tried this, it wont works :
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 路由变成这样:
I want to make my websocket route become like this :
spring:
cloud:
gateway:
routes:
- id: hello-world-route
uri: lb://hello-world:8081
predicates:
- Path=/hello
推荐答案
你可以看看这个issue:网关
you can have a look at this issue: gateway
它应该使用这种方式工作:
and it should works by using this way:
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/**
如果您使用发现客户端,则无需设置端口,只需使用服务名称即可.
and if you use discovery client, you need not to set the port, just use the service name.
这篇关于如何将 spring 云网关路由到 websocket 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文