All Projects → YeautyYE → Netty Websocket Spring Boot Starter

YeautyYE / Netty Websocket Spring Boot Starter

Licence: apache-2.0
🚀 lightweight high-performance WebSocket framework ( 轻量级、高性能的WebSocket框架)

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Netty Websocket Spring Boot Starter

Him Netty
开源的H5即时聊天系统 spring-boot + netty + protobuf + vue ~
Stars: ✭ 194 (-78.08%)
Mutual labels:  spring-boot, im, websocket, netty
Him Vue
开源的H5即时聊天系统 spring-boot + netty + protobuf + vue ~
Stars: ✭ 142 (-83.95%)
Mutual labels:  spring-boot, im, websocket, netty
Easychatandroidclient
EasyChat是一个开源的社交类的App。主要包含消息、好友、群组等相关的IM核心功能。部分界面参照了QQ、微信等相关社交APP。EasyChat APP整体采用MVVM模式,基于JetPack(Lifecycle,LiveData,ViewModel,Room)构建
Stars: ✭ 64 (-92.77%)
Mutual labels:  chat, im, netty
Gochat
goim server write by golang !🚀
Stars: ✭ 1,144 (+29.27%)
Mutual labels:  chat, im, websocket
Javaquarkbbs
基于Spring Boot实现的一个简易的Java社区
Stars: ✭ 755 (-14.69%)
Mutual labels:  spring-boot, websocket, netty
Nettychat
基于Netty+TCP+Protobuf实现的Android IM库,包含Protobuf序列化、TCP拆包与粘包、长连接握手认证、心跳机制、断线重连机制、消息重发机制、读写超时机制、离线消息、线程池等功能。
Stars: ✭ 1,979 (+123.62%)
Mutual labels:  chat, im, netty
Inchat
一个轻量级、高效率的支持多端(应用与硬件Iot)的可分布式、异步网络应用通讯框架
Stars: ✭ 654 (-26.1%)
Mutual labels:  asynchronous, chat, im
Spring Boot Websocket Chat Demo
Spring Boot WebSocket Chat Demo with SockJS fallback and STOMP protocol
Stars: ✭ 726 (-17.97%)
Mutual labels:  spring-boot, chat, websocket
T Io
解决其它网络框架没有解决的用户痛点,让天下没有难开发的网络程序
Stars: ✭ 1,331 (+50.4%)
Mutual labels:  im, websocket, netty
Mmorpg
springboot编写的轻量级高性能mmorpg手游服务端框架,基本功能逐渐完善中。
Stars: ✭ 309 (-65.08%)
Mutual labels:  spring-boot, websocket, netty
Jetlinks Community
JetLinks 基于Java8,Spring Boot 2.x ,WebFlux,Netty,Vert.x,Reactor等开发, 是一个全响应式的企业级物联网平台。支持统一物模型管理,多种设备,多种厂家,统一管理。统一设备连接管理,多协议适配(TCP,MQTT,UDP,CoAP,HTTP等),屏蔽网络编程复杂性,灵活接入不同厂家不同协议等设备。实时数据处理,设备告警,消息通知,数据转发。地理位置,数据可视化等。能帮助你快速建立物联网相关业务系统。
Stars: ✭ 2,405 (+171.75%)
Mutual labels:  spring-boot, websocket, netty
Kingim
KingIM是基于layim的websocket即时通讯系统,底层使用netty。
Stars: ✭ 538 (-39.21%)
Mutual labels:  im, websocket, netty
Im
IM server based on netty. Provides a client jar. Integrate with your own login system.基于netty实现的IM服务端,提供客户端jar包,可集成自己的登录系统
Stars: ✭ 490 (-44.63%)
Mutual labels:  spring-boot, im, netty
Angular Chat
(IM App)Chat App built using Angular and Socket.io
Stars: ✭ 12 (-98.64%)
Mutual labels:  chat, im, websocket
Fastbootweixin
基于Spring Boot的注解驱动式公众号极速开发框架,用注解重新定义公众号开发
Stars: ✭ 640 (-27.68%)
Mutual labels:  spring-boot, annotation
Xz wechat
微信聊天框架搭建,高仿微信聊天框架,一步步学习聊天框架的搭建
Stars: ✭ 634 (-28.36%)
Mutual labels:  chat, im
Brpc Java
Java implementation for Baidu RPC, multi-protocol & high performance RPC.
Stars: ✭ 647 (-26.89%)
Mutual labels:  spring-boot, netty
Lhttp
go websocket, a better way to buid your IM server
Stars: ✭ 603 (-31.86%)
Mutual labels:  im, websocket
Node Chat
💬 Chat application built with NodeJS and Material Design
Stars: ✭ 646 (-27.01%)
Mutual labels:  chat, websocket
Websocket Chat
Websocket based group chat app built with socket.io and react.
Stars: ✭ 689 (-22.15%)
Mutual labels:  chat, websocket

netty-websocket-spring-boot-starter License

中文文档 (Chinese Docs)

About

netty-websocket-spring-boot-starter will help you develop WebSocket server by using Netty in spring-boot,it is easy to develop by using annotation like spring-websocket

Requirement

  • jdk version 1.8 or 1.8+

Quick Start

  • add Dependencies:
	<dependency>
		<groupId>org.yeauty</groupId>
		<artifactId>netty-websocket-spring-boot-starter</artifactId>
		<version>0.10.0</version>
	</dependency>
  • annotate @ServerEndpoint on endpoint class,and annotate @BeforeHandshake,@OnOpen,@OnClose,@OnError,@OnMessage,@OnBinary,@OnEvent on the method. e.g.
@ServerEndpoint(path = "/ws/{arg}")
public class MyWebSocket {

    @BeforeHandshake
    public void handshake(Session session, HttpHeaders headers, @RequestParam String req, @RequestParam MultiValueMap reqMap, @PathVariable String arg, @PathVariable Map pathMap){
        session.setSubprotocols("stomp");
        if (!"ok".equals(req)){
            System.out.println("Authentication failed!");
            session.close();
        }
    }
    
    @OnOpen
    public void onOpen(Session session, HttpHeaders headers, @RequestParam String req, @RequestParam MultiValueMap reqMap, @PathVariable String arg, @PathVariable Map pathMap){
        System.out.println("new connection");
        System.out.println(req);
    }

    @OnClose
    public void onClose(Session session) throws IOException {
       System.out.println("one connection closed"); 
    }

    @OnError
    public void onError(Session session, Throwable throwable) {
        throwable.printStackTrace();
    }

    @OnMessage
    public void onMessage(Session session, String message) {
        System.out.println(message);
        session.sendText("Hello Netty!");
    }

    @OnBinary
    public void onBinary(Session session, byte[] bytes) {
        for (byte b : bytes) {
            System.out.println(b);
        }
        session.sendBinary(bytes); 
    }

    @OnEvent
    public void onEvent(Session session, Object evt) {
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent idleStateEvent = (IdleStateEvent) evt;
            switch (idleStateEvent.state()) {
                case READER_IDLE:
                    System.out.println("read idle");
                    break;
                case WRITER_IDLE:
                    System.out.println("write idle");
                    break;
                case ALL_IDLE:
                    System.out.println("all idle");
                    break;
                default:
                    break;
            }
        }
    }

}
  • use Websocket client to connect ws://127.0.0.1:80/ws/xxx

Annotation

@ServerEndpoint

declaring ServerEndpointExporter in Spring configuration,it will scan for WebSocket endpoints that be annotated with ServerEndpoint . beans that be annotated with ServerEndpoint will be registered as a WebSocket endpoint. all configurations are inside this annotation ( e.g. @ServerEndpoint("/ws") )

@BeforeHandshake

when there is a connection accepted,the method annotated with @BeforeHandshake will be called
classes which be injected to the method are:Session,HttpHeaders...

@OnOpen

when there is a WebSocket connection completed,the method annotated with @OnOpen will be called
classes which be injected to the method are:Session,HttpHeaders...

@OnClose

when a WebSocket connection closed,the method annotated with @OnClose will be called classes which be injected to the method are:Session

@OnError

when a WebSocket connection throw Throwable, the method annotated with @OnError will be called classes which be injected to the method are:Session,Throwable

@OnMessage

when a WebSocket connection received a message,the method annotated with @OnMessage will be called classes which be injected to the method are:Session,String

@OnBinary

when a WebSocket connection received the binary,the method annotated with @OnBinary will be called classes which be injected to the method are:Session,byte[]

@OnEvent

when a WebSocket connection received the event of Netty,the method annotated with @OnEvent will be called classes which be injected to the method are:Session,Object

Configuration

all configurations are configured in @ServerEndpoint's property

property default description
path "/" path of WebSocket can be aliased for value
host "0.0.0.0" host of WebSocket."0.0.0.0" means all of local addresses
port 80 port of WebSocket。if the port equals to 0,it will use a random and available port(to get the port Multi-Endpoint)
bossLoopGroupThreads 0 num of threads in bossEventLoopGroup
workerLoopGroupThreads 0 num of threads in workerEventLoopGroup
useCompressionHandler false whether add WebSocketServerCompressionHandler to pipeline
optionConnectTimeoutMillis 30000 the same as ChannelOption.CONNECT_TIMEOUT_MILLIS in Netty
optionSoBacklog 128 the same as ChannelOption.SO_BACKLOG in Netty
childOptionWriteSpinCount 16 the same as ChannelOption.WRITE_SPIN_COUNT in Netty
childOptionWriteBufferHighWaterMark 64*1024 the same as ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK in Netty,but use ChannelOption.WRITE_BUFFER_WATER_MARK in fact.
childOptionWriteBufferLowWaterMark 32*1024 the same as ChannelOption.WRITE_BUFFER_LOW_WATER_MARK in Netty,but use ChannelOption.WRITE_BUFFER_WATER_MARK in fact.
childOptionSoRcvbuf -1(mean not set) the same as ChannelOption.SO_RCVBUF in Netty
childOptionSoSndbuf -1(mean not set) the same as ChannelOption.SO_SNDBUF in Netty
childOptionTcpNodelay true the same as ChannelOption.TCP_NODELAY in Netty
childOptionSoKeepalive false the same as ChannelOption.SO_KEEPALIVE in Netty
childOptionSoLinger -1 the same as ChannelOption.SO_LINGER in Netty
childOptionAllowHalfClosure false the same as ChannelOption.ALLOW_HALF_CLOSURE in Netty
readerIdleTimeSeconds 0 the same as readerIdleTimeSeconds in IdleStateHandler and add IdleStateHandler to pipeline when it is not 0
writerIdleTimeSeconds 0 the same as writerIdleTimeSeconds in IdleStateHandler and add IdleStateHandler to pipeline when it is not 0
allIdleTimeSeconds 0 the same as allIdleTimeSeconds in IdleStateHandler and add IdleStateHandler to pipeline when it is not 0
maxFramePayloadLength 65536 Maximum allowable frame payload length.
useEventExecutorGroup true Whether to use another thread pool to perform time-consuming synchronous business logic
eventExecutorGroupThreads 16 num of threads in bossEventLoopGroup
sslKeyPassword ""(mean not set) the same as server.ssl.key-password in spring-boot
sslKeyStore ""(mean not set) the same as server.ssl.key-store in spring-boot
sslKeyStorePassword ""(mean not set) the same as server.ssl.key-store-password in spring-boot
sslKeyStoreType ""(mean not set) the same as server.ssl.key-store-type in spring-boot
sslTrustStore ""(mean not set) the same as server.ssl.trust-store in spring-boot
sslTrustStorePassword ""(mean not set) the same as server.ssl.trust-store-password in spring-boot
sslTrustStoreType ""(mean not set) the same as server.ssl.trust-store-type in spring-boot
corsOrigins {}(mean not set) the same as @CrossOrigin#origins in spring-boot
corsAllowCredentials ""(mean not set) the same as @CrossOrigin#allowCredentials in spring-boot

Configuration by application.properties

You can get the configurate of application.properties by using ${...} placeholders. for example:

  • first,use ${...} in @ServerEndpoint
@ServerEndpoint(host = "${ws.host}",port = "${ws.port}")
public class MyWebSocket {
    ...
}
  • then configurate in application.properties
ws.host=0.0.0.0
ws.port=80

Custom Favicon

The way of configure favicon is the same as spring-boot.If favicon.ico is presented in the root of the classpath,it will be automatically used as the favicon of the application.the example is following:

src/
  +- main/
      +- java/
      |   + <source code>
      +- resources/
          +- favicon.ico

Custom Error Pages

The way of configure favicon is the same as spring-boot.you can add a file to an /public/error folder.The name of the error page should be the exact status code or a series mask.the example is following:

src/
  +- main/
      +- java/
      |   + <source code>
      +- resources/
          +- public/
              +- error/
              |   +- 404.html
              |   +- 5xx.html
              +- <other public assets>

Multi Endpoint

  • base on Quick-Start,use annotation @ServerEndpoint and @Component in classes which hope to become a endpoint.
  • you can get all socket addresses in ServerEndpointExporter.getInetSocketAddressSet().
  • when there are different addresses(different host or different port) in WebSocket,they will use different ServerBootstrap instance.
  • when the addresses are the same,but path is different,they will use the same ServerBootstrap instance.
  • when multiple port of endpoint is 0 ,they will use the same random port
  • when multiple port of endpoint is the same as the path,host can't be set as "0.0.0.0",because it means it binds all of the addresses

Change Log

0.8.0

  • Auto-Configuration

0.9.0

  • Support RESTful by @PathVariable
  • Get param by@RequestParam from query
  • Remove ParameterMap ,instead of @RequestParam MultiValueMap
  • Add @BeforeHandshake annotation,you can close the connect before handshake
  • Set sub-protocol in @BeforeHandshake event
  • Remove the @Component on endpoint class
  • Update Netty version to 4.1.44.Final

0.9.1

  • Bug fixed : it was null when using @RequestParam MultiValueMap to get value
  • Update Netty version to 4.1.45.Final

0.9.2

  • There are compatibility version under 0.8.0 that can configure the ServerEndpointExporter manully

0.9.3

  • Bug fixed :when there is no @BeforeHandshake , NullPointerException will appear

0.9.4

  • Bug fixed :when there is no @BeforeHandshake , Session in OnOpen is null

0.9.5

  • Bug fixed :Throwable in OnError event is null

0.10.0

  • Modified the default value of bossLoopGroupThreads to 1
  • Supports configuring useEventExecutorGroup to run synchronous and time-consuming business logic in EventExecutorGroup, so that the I/O thread is not blocked by a time-consuming task
  • SSL supported
  • CORS supported
  • Update Netty version to 4.1.49.Final
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].