java socket 端口复用_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/asrws://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 {

}

来源:https://www.cnblogs.com/passedbylove/p/12061120.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值