java - Reactor TcpServer 丢弃传入连接
问题描述
拒绝/丢弃到Reactor TcpServer的传入连接的正确方法是什么?
我目前有以下内容:
TcpServer.create()
.doOnConnection {
if (notAllowed(it.address()) {
throw IllegalStateException("Connection from ${it.address()} denied")
}
}
.handle(...)
.bindNow()
它似乎正在工作,它成功地从我notAllowed
列表中的远程地址断开连接。但是每次将堆栈跟踪打印到控制台时,通常看起来并不好。
拒绝某些与 TcpServer 的连接的正确方法是什么?
解决方案
我会推荐你而不是 throwing IllegalStateException
,只需调用Connection#dispose
TcpServer.create()
.doOnConnection {
if (notAllowed(it.address()) {
it.dispose()
}
}
.handle(...)
.bindNow()
推荐阅读
- laravel - 找不到模块:错误:无法解析“../App.vue”
- haskell - 向仆人 OpenAPI 规范添加描述
- android-studio - Flutter 升级后 TextField 损坏
- python - 根据 EXIF 数据重命名视频文件
- r - 如何在不同的ggplot类型之间切换?
- typescript - 如何将 `ConstructorParameter` 实用程序与接受泛型的类型一起使用?
- php - Prestashop 后台在 Paiement 和 transporter 页面上显示错误
- graph - Gremlin 是否可以从内部步骤中选择数据
- javascript - MeteorJS 将 nonce 添加到内联 CSS
- reactjs - 根据 API 响应更改类