简体   繁体   English

在使用Netty的HTTP持久连接上限制每秒的事务数(http客户端)

[英]Limit the number of transaction per seconds on HTTP persistent connection Using Netty (http client)

Is there any mechanism/api by which I can control TPS hits from http client? 是否可以通过任何机制/ API控制来自http客户端的TPS命中率?

From HTTP client, I need to control numbers of hits to rest services (my HTTP client will hit to server in controlled manner). 从HTTP客户端,我需要控制命中休息服务的次数(我的HTTP客户端将以受控方式命中服务器)。

you can close it immediately by adding a Netty's IpFilterHandler to server pipeline as the first handler. 您可以通过将Netty的IpFilterHandler作为第一个处理程序添加到服务器管道来立即将其关闭。 It will also stop propagating the upstream channel state events for filtered connection too. 它还将停止传播上行通道状态事件以进行过滤的连接。

 @ChannelHandler.Sharable
 public class FilterIPHandler extends IpFilteringHandlerImpl {
 private final Set<InetSocketAddress> deniedIP;

public filter(Set<InetSocketAddress> deniedIP) {
     this.deniedIP = deniedIP;
 }

 @Override
 protected boolean isAnAccpetedIP(ChannelHandlerContext ctx, ChannelEvent e,  InetSocketAddress inetSocketAddress) throws Exception {
       return !deniedIP.contains(inetSocketAddress);
 }
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM