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 {
}
netty-websocket-spring-boot-starter不同url端口复用的更多相关文章
- Druid Spring Boot Starter 从配置到简单运行 -解决zone不匹配 -解决dataSource加载失败
Druid Spring Boot Starter 中文 | English Druid Spring Boot Starter 用于帮助你在Spring Boot项目中轻松集成Druid数据库连接池 ...
- Spring Boot Starter 介绍
http://www.baeldung.com/spring-boot-starters 作者:baeldung 译者:http://oopsguy.com 1.概述 依赖管理是任何复杂项目的关键部分 ...
- spring -boot s-tarter 详解
Starter POMs是可以包含到应用中的一个方便的依赖关系描述符集合.你可以获取所有Spring及相关技术的一站式服务,而不需要翻阅示例代码,拷贝粘贴大量的依赖描述符.例如,如果你想使用Sprin ...
- Spring Boot (一): Spring Boot starter自定义
前些日子在公司接触了spring boot和spring cloud,有感于其大大简化了spring的配置过程,十分方便使用者快速构建项目,而且拥有丰富的starter供开发者使用.但是由于其自动化配 ...
- SpringBoot 之Spring Boot Starter依赖包及作用
Spring Boot 之Spring Boot Starter依赖包及作用 spring-boot-starter 这是Spring Boot的核心启动器,包含了自动配置.日志和YAML. spri ...
- Spring Boot Starter列表
转自:http://blog.sina.com.cn/s/blog_798f713f0102wiy5.html Spring Boot Starter 基本的一共有43种,具体如下: 1)spring ...
- 自己写spring boot starter
自己写spring boot starter 学习了:<spring boot实战>汪云飞著 6.5.4节 pom.xml <project xmlns="http://m ...
- 一个简单易上手的短信服务Spring Boot Starter
前言 短信服务在用户注册.登录.找回密码等相关操作中,可以让用户使用更加便捷,越来越多的公司都采用短信验证的方式让用户进行操作,从而提高用户的实用性. Spring Boot Starter 由于 S ...
- Spring boot starter pom的依赖关系说明
Spring Boot 通过starter依赖为项目的依赖管理提供帮助.starter依赖起始就是特殊的maven依赖,利用了传递依赖解析,把常用库聚合在一起,组成了几个为特定功能而定制的依赖. sp ...
- 创建自己的Spring Boot Starter
抽取通用模块作为项目的一个spring boot starter.可参照mybatis的写法. IDEA创建Empty Project并添加如下2个module,一个基本maven模块,另一个引入sp ...
随机推荐
- Python 基础-> 字符串,数字,变量
Python 基础:字符串,数字,变量 1. 字符串 (信息的一种表达方式) a. 使用引号创建字符串 b. 单引号,双引号,三引号: ', ", ''', ""&quo ...
- 在linux系统中如何通过shell脚本批量设置redis键值对
业务逻辑:批量设置redis中手机号的验证码为888888: 准备shell脚本如下:将18888888100~18888888110的手机号验证码设置为888888: #!/bin/bash ;i& ...
- wordpress调用文章摘要,若无摘要则自动截取文章内容字数做为摘要
以下是调用指定分类文章列表的一个方法,作者如果有填写文章摘要则直接调用摘要:如果文章摘要忘记写了则自动截取文章内容字数做为摘要.这个方法也适用于调用description标签 <ul> & ...
- LeetCode 911. Online Election
原题链接在这里:https://leetcode.com/problems/online-election/ 题目: In an election, the i-th vote was cast fo ...
- MongoDB 实现 create table tab2 as select
1. var result = db.foo.aggregate(...);db.bar.insert(result.result); 2. var temp1 = db.mtb1.find(name ...
- MongoDB 查看当前配置
MongoDB Enterprise > db.adminCommand({getParameter:"*"}) MongoDB Enterprise > db._ad ...
- 用nginx代理请求,django后台静态文件找不到的问题
使用谷歌开发者工具,查看静态文件的地址,把相应的地址配置到nginx中 默认的django后台静态文件的路径是 /usr/local/lib/python3.6/site-packages/djang ...
- 数列的前$n$项和$S_n$的求法
相关公式 ①等差数列的\(S_n=\cfrac{n(a_1+a_n)}{2}=na_1+\cfrac{n(n-1)\cdot d}{2}\) ②等比数列的\(S_n=\left\{\begin{arr ...
- redis三种模式对比
模式类型 主从模式(redis2.8版本之前的模式).哨兵sentinel模式(redis2.8及之后的模式).redis cluster模式(redis3.0版本之后) 主从模式原理 同Mysql主 ...
- ubuntu下Java通过JNI调用C
下面看一个实例,如下: public class TestJNI { static { System.loadLibrary("diaoyong"); // 程序在加载时,自动加载 ...