Eric Martin 3225470df5 Merge pull request #8125 from eugenp/revert-8119-BAEL-3275-2
Revert "BAEL-3275: Using blocking queue for pub-sub"
2019-10-31 20:43:47 -05:00

46 lines
1.5 KiB
Java

package com.baeldung.weather;
import io.reactivex.Flowable;
import io.vertx.core.http.RequestOptions;
import io.vertx.reactivex.core.http.HttpClient;
import io.vertx.reactivex.core.http.HttpClientRequest;
import io.vertx.reactivex.core.http.HttpClientResponse;
import static java.lang.String.format;
class MetaWeatherClient {
private static RequestOptions metawether = new RequestOptions()
.setHost("www.metaweather.com")
.setPort(443)
.setSsl(true);
/**
* @return A flowable backed by vertx that automatically sends an HTTP request at soon as the first subscription is received.
*/
private static Flowable<HttpClientResponse> autoPerformingReq(HttpClient httpClient, String uri) {
HttpClientRequest req = httpClient.get(new RequestOptions(metawether).setURI(uri));
return req.toFlowable()
.doOnSubscribe(subscription -> req.end());
}
static Flowable<HttpClientResponse> searchByCityName(HttpClient httpClient, String cityName) {
HttpClientRequest req = httpClient.get(
new RequestOptions()
.setHost("www.metaweather.com")
.setPort(443)
.setSsl(true)
.setURI(format("/api/location/search/?query=%s", cityName)));
return req
.toFlowable()
.doOnSubscribe(subscription -> req.end());
}
static Flowable<HttpClientResponse> getDataByPlaceId(HttpClient httpClient, long placeId) {
return autoPerformingReq(
httpClient,
format("/api/location/%s/", placeId));
}
}