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 {
    }
  • 相关阅读:
    2020下第八周总结
    《程序员的自我修养》——阅读感悟1
    2020下第七周总结
    【基础组件11】hdfs与hbase
    【基础组件10】hadoop拓展(三)NameNode工作机制
    【基础组件9】hadoop入门(二)启动节点、集群、hdfs查看文件系统、清数据
    【基础组件8】hadoop入门(一)集群搭建/ HDFS-HA高可用搭建
    【基础组件7】flink入门(一)集群搭建、实时数据处理
    【基础组件6】kafkamanager安装部署+详细参数讲解+使用教程
    【基础组件5】kafka入门(一)集群搭建+常用命令+基本原理+存储分析
  • 原文地址:https://www.cnblogs.com/passedbylove/p/12061120.html
Copyright © 2011-2022 走看看