All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.ribbon.examples.netty.http.SimpleGet Maven / Gradle / Ivy

package com.netflix.ribbon.examples.netty.http;

import com.netflix.ribbon.transport.netty.RibbonTransport;
import com.netflix.ribbon.transport.netty.http.LoadBalancingHttpClient;
import io.netty.buffer.ByteBuf;
import io.reactivex.netty.protocol.http.client.HttpClientRequest;
import io.reactivex.netty.protocol.http.client.HttpClientResponse;
import rx.functions.Action1;

import java.nio.charset.Charset;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class SimpleGet {
    @edu.umd.cs.findbugs.annotations.SuppressWarnings
    public static void main(String[] args) throws Exception {
        LoadBalancingHttpClient client = RibbonTransport.newHttpClient();
        HttpClientRequest request = HttpClientRequest.createGet("http://www.google.com/");
        final CountDownLatch latch = new CountDownLatch(1);
        client.submit(request)
            .toBlocking()
            .forEach(new Action1>() {
                @Override
                public void call(HttpClientResponse t1) {
                    System.out.println("Status code: " + t1.getStatus());
                    t1.getContent().subscribe(new Action1() {

                        @Override
                        public void call(ByteBuf content) {
                            System.out.println("Response content: " + content.toString(Charset.defaultCharset()));
                            latch.countDown();
                        }
                        
                    });
                }
            });
        latch.await(2, TimeUnit.SECONDS);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy