Search in sources :

Example 1 with RequestHandler

use of io.reactivex.netty.protocol.http.server.RequestHandler in project feign by OpenFeign.

the class RealRequestBenchmarks method setup.

@Setup
public void setup() {
    server = RxNetty.createHttpServer(SERVER_PORT, new RequestHandler<ByteBuf, ByteBuf>() {

        public rx.Observable handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
            return response.flush();
        }
    });
    server.start();
    client = new OkHttpClient();
    client.setRetryOnConnectionFailure(false);
    okFeign = Feign.builder().client(new feign.okhttp.OkHttpClient(client)).target(FeignTestInterface.class, "http://localhost:" + SERVER_PORT);
    queryRequest = new Request.Builder().url("http://localhost:" + SERVER_PORT + "/?Action=GetUser&Version=2010-05-08&limit=1").build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) RequestHandler(io.reactivex.netty.protocol.http.server.RequestHandler) HttpServerRequest(io.reactivex.netty.protocol.http.server.HttpServerRequest) HttpServerResponse(io.reactivex.netty.protocol.http.server.HttpServerResponse) Request(okhttp3.Request) HttpServerRequest(io.reactivex.netty.protocol.http.server.HttpServerRequest) Setup(org.openjdk.jmh.annotations.Setup)

Example 2 with RequestHandler

use of io.reactivex.netty.protocol.http.server.RequestHandler in project Hystrix by Netflix.

the class HystrixMetricsStreamHandlerTest method createServer.

// We try a few times in case we hit into used port.
private HttpServer<ByteBuf, ByteBuf> createServer() {
    Random random = new Random();
    Exception error = null;
    for (int i = 0; i < 3 && server == null; i++) {
        port = 10000 + random.nextInt(50000);
        try {
            return RxNetty.newHttpServerBuilder(port, new HystrixMetricsStreamHandler<ByteBuf, ByteBuf>(DEFAULT_HYSTRIX_PREFIX, DEFAULT_INTERVAL, new // Application handler
            RequestHandler<ByteBuf, ByteBuf>() {

                @Override
                public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
                    return Observable.empty();
                }
            })).build().start();
        } catch (Exception e) {
            error = e;
        }
    }
    throw new RuntimeException("Cannot initialize RxNetty server", error);
}
Also used : Random(java.util.Random) RequestHandler(io.reactivex.netty.protocol.http.server.RequestHandler) HttpServerRequest(io.reactivex.netty.protocol.http.server.HttpServerRequest) HttpServerResponse(io.reactivex.netty.protocol.http.server.HttpServerResponse) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

HttpServerRequest (io.reactivex.netty.protocol.http.server.HttpServerRequest)2 HttpServerResponse (io.reactivex.netty.protocol.http.server.HttpServerResponse)2 RequestHandler (io.reactivex.netty.protocol.http.server.RequestHandler)2 ByteBuf (io.netty.buffer.ByteBuf)1 Random (java.util.Random)1 OkHttpClient (okhttp3.OkHttpClient)1 Request (okhttp3.Request)1 Setup (org.openjdk.jmh.annotations.Setup)1