【橘子websocket】如何基于vertx来构建websocket聊天室(上)

简介

websocket的概念我们就不说了,网上已经说烂了,具体更加权威的内容可以去看RFC6455
我们这里只来操作一下如何在实际开发中构建websocket服务。如果是springboot技术栈的话,其实很简单,就是几个注解的问题。不得不说springboot真的很方便。可以参考springboot的官方文档springboot websocket
我们这里不用springboot,我们来使用vertx来构建。至于什么是vertx可以参考vertx的官网vertx
简单来说就是他是基于netty构建的一个响应式的包,并且在这个基础上开发出了一套相对完整的生态。今天我们单说他的websocket实现。

一、环境依赖

jdk11 实际jdk8也行
maven:3.6
idea

具体的包依赖如下:

<properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
    <maven-shade-plugin.version>3.2.4</maven-shade-plugin.version>
    <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
    <exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>
    <logback.version>1.5.12</logback.version>


    <vertx.version>4.0.3</vertx.version>
    <junit-jupiter.version>5.6.0</junit-jupiter.version>
    <javafaker.version>1.0.2</javafaker.version>
    <lombok.version>1.18.36</lombok.version>
    <fastjson2.version>2.0.52</fastjson2.version>
    <jackson-databind.version>2.17.3</jackson-databind.version>
    <junit-jupiter.version>5.6.2</junit-jupiter.version>
    <junit-platform-surefire-provider.version>1.0.1</junit-platform-surefire-provider.version>
    <assertj-core.version>3.8.0</assertj-core.version>
    <logback-classic.version>1.5.12</logback-classic.version>

</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.vertx</groupId>
            <artifactId>vertx-stack-depchain</artifactId>
            <version>${vertx.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-bom</artifactId>
            <version>2.3.2</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-core</artifactId>
        <version>${vertx.version}</version>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>${jackson-databind.version}</version>
    </dependency>

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>${logback-classic.version}</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>${logback.version}</version>
    </dependency>
    <dependency>
        <groupId>com.github.javafaker</groupId>
        <artifactId>javafaker</artifactId>
        <v
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值