zoukankan      html  css  js  c++  java
  • netty-websocket-spring-boot-starter不同url端口复用

    netty-websocket-spring-boot-starter是一个基于netty的websocket服务端,目前笔者使用的版本依托于Springboot。
    官方网址https://github.com/YeautyYE/netty-websocket-spring-boot-starter

    本文将帮你解决以下问题:
    ws://www.aaa.com/api/asr
    ws://www.aaa.com/api/tts
    共用一个JVM,减少不必要的内存开销。
    当然示例很简单,在官方文档也有说。

    以下是代码
    application.yml
    spring:  
      netty-websocket:
         host: 0.0.0.0
         port: 80 #默认80可不填写
    注意事项:prefix = "spring.netty-websocket"需要和配置文件里面的路径一直,这个属性文件查找的前缀,会有一些默认的值。比如
    path="/",port=80,如果是这些值,在配置文件里可以不写,只写host

    RealTimeTTSEndpoint.java负责处理 /api/tts相关业务
    import org.springframework.stereotype.Component;
    import org.springframework.util.CollectionUtils;
    import org.yeauty.annotation.OnClose;
    import org.yeauty.annotation.OnError;
    import org.yeauty.annotation.OnMessage;
    import org.yeauty.annotation.OnOpen;
    import org.yeauty.annotation.ServerEndpoint;
    import org.yeauty.pojo.ParameterMap;
    import org.yeauty.pojo.Session;
    
    import javax.annotation.PostConstruct;
    import javax.annotation.PreDestroy;
    import java.net.URI;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Objects;
    import java.util.Set;
    import java.util.concurrent.ConcurrentHashMap;
    import java.util.concurrent.CountDownLatch;
    import java.util.concurrent.ExecutorService;
    
    @ServerEndpoint(prefix = "spring.netty-websocket",path = "/api/tts")
    @Component
    @Slf4j
    public class RealTimeTTSEndpoint {
    }
    RealTimeASREndpoint.java负责处理/api/asr相关业务
    import io.netty.buffer.ByteBuf;
    import io.netty.buffer.Unpooled;
    import io.netty.handler.timeout.IdleStateEvent;
    import lombok.extern.slf4j.Slf4j;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.stereotype.Component;
    import org.springframework.util.CollectionUtils;
    import org.springframework.util.StringUtils;
    import org.yeauty.annotation.OnBinary;
    import org.yeauty.annotation.OnClose;
    import org.yeauty.annotation.OnError;
    import org.yeauty.annotation.OnEvent;
    import org.yeauty.annotation.OnMessage;
    import org.yeauty.annotation.OnOpen;
    import org.yeauty.annotation.ServerEndpoint;
    import org.yeauty.pojo.Session;
    
    import javax.annotation.PostConstruct;
    import javax.annotation.PreDestroy;
    import java.io.IOException;
    import java.net.URI;
    import java.net.URISyntaxException;
    import java.nio.file.Files;
    import java.nio.file.Path;
    import java.nio.file.Paths;
    import java.time.LocalDate;
    import java.time.ZoneId;
    import java.time.format.DateTimeFormatter;
    import java.util.Iterator;
    import java.util.Map;
    import java.util.Objects;
    import java.util.Set;
    import java.util.concurrent.ConcurrentHashMap;
    import java.util.concurrent.ExecutionException;
    import java.util.concurrent.ExecutorService;
    import java.util.concurrent.Future;
    import java.util.concurrent.TimeUnit;
    import java.util.concurrent.TimeoutException;
    
    @ServerEndpoint(prefix = "spring.netty-websocket",path = "/api/asr")
    @Component
    @Slf4j
    public class RealTimeASREndpoint {
    }
  • 相关阅读:
    python3线程介绍01(如何启动和调用线程)
    CentOS7 设置静态 ip
    png2ico
    Thunderbird 配置 QQ mail
    memcached 开机启动 (Ubuntu)
    CentOS7 docker 安装的 container-selinux 问题及解决
    YAML 的基本语法
    docker 的脚本化安装和使用
    解决Windows下 “setup.py build” 时出现错误 ” error: Unable to find vcvarsall.bat”
    Electric Fence
  • 原文地址:https://www.cnblogs.com/passedbylove/p/12061120.html
Copyright © 2011-2022 走看看