Git Product home page Git Product logo

websocket_netty's Introduction

Netty实现的websocket推送框架

2018-05-24 更新

主要改动

1. 冗余代码和过度设计的优化
2. 基于spring-websocket框架,重新设计的
3. 开放 com.dragsun.websocket.handler.websocket.AbstractWebSocketHandler 与 com.dragsun.websocket.handler.websocket.WebSocketHandler 接口,自己根据业务需求去实现
4. 分模块,便于接入自己的项目
5.//TODO 添加控制台和统计监控

结构

    基于spring 容器
    - 项目新增springboot 的启动,用于一些web操作
    - 有直接通过App.java 启动程序    
    - 后续会添加 web 控制台,监控连接数和统计面板 (dashboard)
    - 划分了模块 :
        dragsun-main 作为程序入口
            resources: spring、springboot 配置文件
            templates: 静态页面和资源文件夹以及测试网页
        websocket-server websocket实现模块
        以及其他模块(bing 微软必应SpeechToText的接入)

WebSocket Netty实现

目的

业务需求,需要向前端浏览器订阅推送业务,接受后端推送,之前用的是amq.js (activemq基于轮询实现),有很大的性能问题和实时性也无法保证; 所以就使用了 netty 实现了个 Websocket 框架

推送需求:有时候需要进行多订阅,对于前端的需求的多消息类型分别接收,后端需要不同订阅的业务进行隔离,各自发送推送,所以又优化了单请求多订阅的功能。

WebSocket 基于H5实现,低版本IE不支持 (ie8)

有时候需要网页和手机端都要一致推送协议,则手机客户端也可能需要实现websocket推送

WebSocket协议(RFC6455)的翻译和官网描述地址

websocket浏览器h5对象,前端api文档 : https://www.w3.org/TR/websockets/

源码与配置

程序入口在 dragsun-main 模块下

在 dragsun-main 模块中的 resources/websocket.xml 的spring 配置文件中配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd    
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd"
>


    <!--<bean id="webSocketHandler" class="com.jason.websocket.speech.bing.BingWebSocketHandler"></bean>-->
    <!--<bean id="webSocketHandler" class="com.dragsun.speech.google.GoogleWebSocketHandler"></bean>-->

    <!--默认处理器-->
    <bean id="webSocketHandler" class="com.jason.websocket.common.SimpleWebSocketHandler"></bean>
    <!--配置-->
    <bean id="wSConfiguration" class="com.dragsun.websocket.server.Configuration">
        <property name="webSocketHandler" ref="webSocketHandler"/>
    </bean>
    <bean id="webSocketNettyServer" class="com.dragsun.websocket.server.WebSocketNettyServer" >
        <property name="port" value="38888" />
        <property name="configuration" ref="wSConfiguration"/>
    </bean>


</beans>

Netty 的Server 处理类在 com.dragsun.websocket.server.WebSocketNettyServer

WebSocket的请求封装与握手,以及心跳机制在类 com.dragsun.websocket.handler.WebSocketChannelHandlerFactory

websocket_netty's People

Contributors

zhuangjiesen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

websocket_netty's Issues

大神,你看我报的错误

F:\jdk1.8\install\jdk1.8\bin\java -Dmaven.multiModuleProjectDirectory=F:\mayun\websocket_netty\WebSocket_Netty\JavaProServer "-Dmaven.home=F:\IDEAIU 2017.2\install\IntelliJ IDEA 2017.2.4\plugins\maven\lib\maven3" "-Dclassworlds.conf=F:\IDEAIU 2017.2\install\IntelliJ IDEA 2017.2.4\plugins\maven\lib\maven3\bin\m2.conf" "-javaagent:F:\IDEAIU 2017.2\install\IntelliJ IDEA 2017.2.4\lib\idea_rt.jar=60904:F:\IDEAIU 2017.2\install\IntelliJ IDEA 2017.2.4\bin" -Dfile.encoding=UTF-8 -classpath "F:\IDEAIU 2017.2\install\IntelliJ IDEA 2017.2.4\plugins\maven\lib\maven3\boot\plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2017.2.4 -s F:\maven-3.3.9\apache-maven-3.3.9-bin\apache-maven-3.3.9\conf\settings.xml -Dmaven.repo.local=F:\maven\repository compile
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for JavaProServer:JavaProServer:jar:1.0-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework:spring-jms:jar -> version 4.3.3.RELEASE vs 4.3.6.RELEASE @ line 412, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building JavaProServer 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ JavaProServer ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory F:\mayun\websocket_netty\WebSocket_Netty\JavaProServer\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ JavaProServer ---
[INFO] No sources to compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.246 s
[INFO] Finished at: 2018-01-29T14:03:00+08:00
[INFO] Final Memory: 12M/217M
[INFO] ------------------------------------------------------------------------

Process finished with exit code 0

你好大神,我遇到问题想问你

我git下您的代码,但是项目跑步起来,提示没有tomcat,然后装上有提示别的错误,不清楚怎么弄了,特别懵,您能帮我看下吗,qq:1521680589谢谢你了

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.