项目作者: ji4597056

项目描述 :
websocket forwarding proxy support for the framework of spring boot and spring cloud
高级语言: Java
项目地址: git://github.com/ji4597056/websocket-forward.git
创建时间: 2017-12-05T08:43:46Z
项目社区:https://github.com/ji4597056/websocket-forward

开源协议:

下载


Websocket Forward

  • The simple library is used to support the forward proxy of websocket for applications which are based in the framework of spring boot.
  • The library is based on JDK8.

Usage

spring-websocket-forward is available from Maven Central.

  1. <dependency>
  2. <groupId>com.github.ji4597056</groupId>
  3. <artifactId>spring-websocket-forward</artifactId>
  4. <version>1.0.2.RELEASE</version>
  5. </dependency>

Who is this for?

Spring Cloud Zuul and Spring Boot Websocket do not support the forwarding proxy of web sockets. However, we usually need the proxy of websocket.

How do I use this?

  • Enable it like so:
  1. @EnableWsForward
  2. @SpringBootApplication
  3. public class Application {
  4. public static void main(String[] args) {
  5. SpringApplication.run(Application.class, args);
  6. }
  7. }
  • Then in your spring application properties(e.g application.yml)
  1. ws:
  2. forward:
  3. enabled: true
  4. handlers:
  5. test:
  6. enabled: true
  7. prefix: /test
  8. uri: /**
  9. serviceId: test-client
  10. allowedOrigins: "*"
  11. withJs: false

With this you can accurately get websockets support from proxied back-end service.

Configuration introduction

property type required default introduction
enabled boolean false true enabled or not
prefix string false null uri route prefix
uri string true null uri
withJs boolean false false with JS or not
forwardPrefix string false null forwarding uri route prefix
serviceId string false null find forwarding addresses from registration center by service id
listOfServers string[] false null find forwarding addresses from list of services if serviceId is not set,eg:localhost:8080
allowedOrigins string[] false “*” allowed origins
handlerClass string false null name of AbstractWsServerHandler class,use global handler if there is not set
interceptorClasses string[] false null name of HandshakeInterceptor class,use global interceptors if there is not set

Remark

if you want to set your own AbstractWsServerHandler or HandshakeInterceptor,config bean of WsHandlerRegistration like:

  1. @Bean
  2. public WsHandlerRegistration wsHandlerRegistration() {
  3. WsHandlerRegistration registration = new DefaultWsHandlerRegistration();
  4. registration.addHandler(new TestWsServerHandler());
  5. registration.addInterceptor(new TestHandshakeInterceptor());
  6. return registration;
  7. }

Then you can set the property of handlerClass or interceptorClasses.