Giter VIP home page Giter VIP logo

websocket-route-spring-boot-starter's Introduction

websocket-route-spring-boot-starter

Websocket Route Spring Book Edition

中文

Support Function:

  • WebsocketRoute

WebsocketRoute:

Make Websocket Cluster More Optional

Websocket

websocket-spring-boot-starter

Quick Start

<!--Adding dependencies to pom. XML-->
        <dependency>
            <artifactId>websocket-route-spring-boot-starter</artifactId>
            <groupId>com.github.thierrysquirrel</groupId>
            <version>1.1.1.4-RELEASE</version>
        </dependency>

configuration file

## application.properties
websocket.route.url=127.0.0.1:9090
websocket.route.relays[0].match-path-prefix=/user
websocket.route.relays[0].relay-bean-name=userRelay

Start Websocket

@SpringBootApplication
public class WebsocketRouteApplication{
    public static void main(String[] args){
        SpringApplication.run(WebsocketRouteApplication.class, args);
    }
}

Getting Started WebsocketRoute

@Component
public class UserRoute implements WebsocketRelayTemplate {
    public static List<String> websocketServerUrl=new ArrayList<> ();
    static {
        /**
         * You Can Use The RPC Tool To Obtain The Cluster URL Address Periodically
         * For Example, Use HTTP To Request URL Storage Server (HttpServer+redis)
         */
        websocketServerUrl.add ("127.0.0.1:8080");
        websocketServerUrl.add ("127.0.0.1:8081");
        websocketServerUrl.add ("127.0.0.1:8082");
    }
    @Override
    public HttpUpgradeMessage relay(HttpRequestMessage requestMessage) throws WebsocketRouteException {
        String uriPath = requestMessage.getUri ();
        Map<String, String> uriParam = requestMessage.getUriParam ();
        HttpHeaders headers = requestMessage.getHeaders ();
//        String hello = uriParam.get ("hello");
//        String localUrl = getLocalUrl (Integer.parseInt (hello));
        String headersUrl = getHeadersUrl (headers);
        headers.set ("ConnectUrl",headersUrl);
        return HttpUpgradeMessageBuilder.builderHttpUpgradeMessage (headersUrl,uriPath,headers);

    }
    public static String getHeadersUrl(HttpHeaders headers){
        /**
         * There Are Many Things That Can Be Done Here
         * Example 1.
         * Team up to join the same server
         * The Team Leader Requests From The URL Server And Gets The URL (The Request Here Can Use A Variety Of Protocols, Such As HTTP + Redis)
         * The Team Leader Assigns The URL To His Teammates.
         * Each Person's Request Header carries The URL And Connects To The Same Server
         * Example 2.
         * Join Friends Server
         * Request Ro Store The URL Of A Friend's Connected Server,(The Request Here Can Use A Variety Of Protocols, Such As HTTP + Redis)
         * The Request Header Carries The URL And Connects To The Same Server
         *
         */
        return headers.get ("world");
    }
    public static String getLocalUrl(int offset){
        return websocketServerUrl.get (offset);
    }
}

Russian flag

websocket-route-spring-boot-starter's People

Contributors

thierrysquirrel avatar

Stargazers

 avatar

Watchers

 avatar

websocket-route-spring-boot-starter's Issues

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.