Giter VIP home page Giter VIP logo

websocket-forward's Introduction

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 weboscket.

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
listOfServices 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.

websocket-forward's People

Contributors

ji4597056 avatar

Watchers

James Cloos avatar wycheng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.