Skip to content

websocket forwarding proxy support for the framework of spring boot and spring cloud

Notifications You must be signed in to change notification settings

ji4597056/websocket-forward

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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.

	<dependency>
		<groupId>com.github.ji4597056</groupId>
		<artifactId>spring-websocket-forward</artifactId>
		<version>1.0.2.RELEASE</version>
	</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:
@EnableWsForward
@SpringBootApplication
public class Application {
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}
}
  • Then in your spring application properties(e.g application.yml)
ws:
  forward:
    enabled: true
    handlers:
      test:
        enabled: true
        prefix: /test
        uri: /**
        serviceId: test-client
        allowedOrigins: "*"
        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:

    @Bean
    public WsHandlerRegistration wsHandlerRegistration() {
        WsHandlerRegistration registration = new DefaultWsHandlerRegistration();
        registration.addHandler(new TestWsServerHandler());
        registration.addInterceptor(new TestHandshakeInterceptor());
        return registration;
    }

Then you can set the property of handlerClass or interceptorClasses.

About

websocket forwarding proxy support for the framework of spring boot and spring cloud

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages