限制vert.x应用程序

问题描述 投票:0回答:1

我有一个vert.x应用程序,它托管在Cloud Foundry上。我必须以InterceptorHandler在Spring中的方式实现限制基于可用内存的请求的限制条件。那么有没有办法在请求实际到达服务器内存之前拦截HTTP请求到服务器?

java spring cloudfoundry vert.x
1个回答
1
投票

我假设您的意图是尽快限制请求,这就是“没有到达内存”的意思。

为此,您可以使用简单的全局处理程序,因为在Vert.x中,每个处理程序都是各种拦截器。

    router.route().handler(ctx -> {
        // Probably you want to check some request properties
       if (isThrottled(ctx)) {
           ctx.response().setStatusCode(504).end();
       }
       else {
           // All is good, continue
           ctx.next();
       }
    });

不过,我还必须注意,与Spring不同,Vert.x具有恒定的内存占用,因为Vert.x使用有限数量的线程。此数字不受传入请求数量的影响。所以我不建议基于内存的限制。

© www.soinside.com 2019 - 2024. All rights reserved.