本文整理汇总了Java中io.vertx.reactivex.core.buffer.Buffer类的典型用法代码示例。如果您正苦于以下问题:Java Buffer类的具体用法?Java Buffer怎么用?Java Buffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Buffer类属于io.vertx.reactivex.core.buffer包,在下文中一共展示了Buffer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: handle
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
@Override
public void handle(RoutingContext rc) {
Long albumId = PathUtil.parseLongParam(rc.pathParam("albumId"));
if (albumId == null) {
rc.next();
return;
}
// Currently there's an issue with rx.Buffer as value type, so workaround with core Buffer
LocalMap<Long, io.vertx.core.buffer.Buffer> covers = rc.vertx().sharedData().getLocalMap("covers");
io.vertx.core.buffer.Buffer cached = covers.get(albumId);
if (cached != null) {
rc.response().end(Buffer.newInstance(cached));
return;
}
download(albumId)
.doOnSuccess(buffer -> covers.put(albumId, buffer.getDelegate()))
.subscribe(rc.response()::end, rc::fail, () -> rc.fail(404));
}
开发者ID:tsegismont,项目名称:vertx-musicstore,代码行数:21,代码来源:CoverHandler.java
示例2: download
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
private Maybe<Buffer> download(Long albumId) {
return dbClient.rxGetConnection().flatMap(sqlConnection -> {
return findAlbum(sqlConnection, albumId).doAfterTerminate(sqlConnection::close);
}).flatMapMaybe(album -> {
String mbAlbumId = album.getString("mbAlbumId");
return mbAlbumId == null ? Maybe.empty() : Maybe.just(mbAlbumId);
}).flatMap(mbAlbumId -> {
return webClient
.getAbs("http://coverartarchive.org")
.uri("/release/" + mbAlbumId + "/front")
.as(BodyCodec.buffer())
.rxSend()
.map(HttpResponse::body)
.toMaybe();
});
}
开发者ID:tsegismont,项目名称:vertx-musicstore,代码行数:17,代码来源:CoverHandler.java
示例3: start
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
@Override
public void start() throws Exception {
MqttClient client = MqttClient.create(vertx);
client.rxConnect(PORT, HOST)
.flatMapPublisher(ack ->
Flowable.interval(1, TimeUnit.SECONDS)
.flatMapSingle(l -> {
JsonObject payload = new JsonObject()
.put("uuid", id)
.put("data",
random.nextInt(100));
return client
.rxPublish("/data",
Buffer.buffer(payload.encode()),
MqttQoS.AT_MOST_ONCE, false, false);
}))
.subscribe();
}
开发者ID:cescoffier,项目名称:various-vertx-demos,代码行数:20,代码来源:Sensor.java
示例4: delegateWithCircuitBreaker
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
private void delegateWithCircuitBreaker(RoutingContext rc) {
HttpEndpoint.rxGetWebClient(discovery, svc -> svc.getName().equals("currency-3rdparty-service"))
.flatMap(client -> {
// TODO
// Use the circuit breaker (circuit) to call the service. Use the rxExecuteCommandWithFallback` method.
// This methods takes 2 parameters: the first one if a function taking a `Future` as parameter and
// needs to report the success or failure on this future. The second method is a function providing
// the fallback result. You must provide a JSON object as response. For the fallback use:
// new JsonObject()
// .put("amount", rc.getBodyAsJson().getDouble("amount"))
// .put("currency", "USD"))
// In the first function, use the given client, emit a POST request on / containing the incoming
// payload (rc.getBodyAsJson()). Extract the response payload as JSON (bodyAsJsonObject). Don't
// forget to subscribe (you can use subscribe(toObserver(fut)). You can have a look to the `delegate`
// method as example.
// -----
return Single.just(new JsonObject().put("amount", 0.0).put("currency", "N/A"));
})
// ----
.map(JsonObject::toBuffer)
.map(Buffer::new)
.subscribe(toObserver(rc));
}
开发者ID:cescoffier,项目名称:vertx-kubernetes-workshop,代码行数:26,代码来源:CurrencyServiceProxy.java
示例5: convertPortfolioToEuro
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
/**
* Method to check the proxy requesting to convert the current portfolio to EUR.
*
* @param rc the routing context
*/
private void convertPortfolioToEuro(RoutingContext rc) {
EventBusService.getServiceProxy(discovery, svc -> svc.getName().equals("portfolio"), PortfolioService.class,
ar -> {
if (ar.failed()) {
rc.fail(ar.cause());
} else {
ar.result().evaluate(res -> {
if (res.failed()) {
rc.fail(res.cause());
} else {
JsonObject payload = new JsonObject().put("amount", res.result()).put("currency", "EUR");
rc.setBody(new Buffer(payload.toBuffer()));
delegateWithCircuitBreaker(rc);
}
});
}
});
}
开发者ID:cescoffier,项目名称:vertx-kubernetes-workshop,代码行数:24,代码来源:CurrencyServiceProxy.java
示例6: callService
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
private Single<HttpResponse<Buffer>> callService(
Pair<ClientRequest, ServiceMetadata> serviceData, HttpMethod method) {
final Single<HttpResponse<Buffer>> httpResponse;
final ClientRequest serviceRequest = serviceData.getLeft();
final ServiceMetadata serviceMetadata = serviceData.getRight();
final HttpRequest<Buffer> request = webClient
.request(method, serviceMetadata.getPort(), serviceMetadata.getDomain(),
serviceRequest.getPath());
updateRequestQueryParams(request, serviceMetadata);
updateRequestHeaders(request, serviceRequest, serviceMetadata);
overrideRequestHeaders(request, serviceMetadata);
if (!serviceRequest.getFormAttributes().isEmpty()) {
httpResponse = request.rxSendForm(serviceRequest.getFormAttributes());
} else {
httpResponse = request.rxSend();
}
return httpResponse;
}
开发者ID:Cognifide,项目名称:knotx,代码行数:24,代码来源:HttpClientFacade.java
示例7: updateRequestHeaders
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
private void updateRequestHeaders(HttpRequest<Buffer> request, ClientRequest serviceRequest,
ServiceMetadata serviceMetadata) {
MultiMap filteredHeaders = getFilteredHeaders(serviceRequest.getHeaders(),
serviceMetadata.getAllowedRequestHeaderPatterns());
filteredHeaders.names().forEach(
headerName -> filteredHeaders.getAll(headerName)
.forEach(value -> request.headers().add(headerName, value)));
if (customRequestHeader.containsKey("name") && customRequestHeader.containsKey("value")) {
request.headers().set(
customRequestHeader.getString("name"),
customRequestHeader.getString("value")
);
}
}
开发者ID:Cognifide,项目名称:knotx,代码行数:17,代码来源:HttpClientFacade.java
示例8: delayFlowable
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
public void delayFlowable(HttpServer server) {
server.requestHandler(request -> {
if (request.method() == HttpMethod.POST) {
// Stop receiving buffers
request.pause();
checkAuth(res -> {
// Now we can receive buffers again
request.resume();
if (res.succeeded()) {
Flowable<Buffer> flowable = request.toFlowable();
flowable.subscribe(buff -> {
// Get buffers
});
}
});
}
});
}
开发者ID:vert-x3,项目名称:vertx-rx,代码行数:23,代码来源:RxifiedExamples.java
示例9: testGet
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
@Test
public void testGet() {
int times = 5;
waitFor(times);
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> req.response().setChunked(true).end("some_content"));
try {
server.listen(ar -> {
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Single<HttpResponse<Buffer>> single = client
.get(8080, "localhost", "/the_uri")
.as(BodyCodec.buffer())
.rxSend();
for (int i = 0; i < times; i++) {
single.subscribe(resp -> {
Buffer body = resp.body();
assertEquals("some_content", body.toString("UTF-8"));
complete();
}, this::fail);
}
});
await();
} finally {
server.close();
}
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:27,代码来源:Rx2Test.java
示例10: testPost
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
@Test
public void testPost() {
int times = 5;
waitFor(times);
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> req.bodyHandler(buff -> {
assertEquals("onetwothree", buff.toString());
req.response().end();
}));
try {
server.listen(ar -> {
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Observable<Buffer> stream = Observable.just(Buffer.buffer("one"), Buffer.buffer("two"), Buffer.buffer("three"));
Single<HttpResponse<Buffer>> single = client
.post(8080, "localhost", "/the_uri")
.rxSendStream(stream);
for (int i = 0; i < times; i++) {
single.subscribe(resp -> complete(), this::fail);
}
});
await();
} finally {
server.close();
}
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:26,代码来源:Rx2Test.java
示例11: testResponseMissingBody
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
@Test
public void testResponseMissingBody() throws Exception {
int times = 5;
waitFor(times);
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> req.response().setStatusCode(403).end());
try {
server.listen(ar -> {
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Single<HttpResponse<Buffer>> single = client
.get(8080, "localhost", "/the_uri")
.rxSend();
for (int i = 0; i < times; i++) {
single.subscribe(resp -> {
assertEquals(403, resp.statusCode());
assertNull(resp.body());
complete();
}, this::fail);
}
});
await();
} finally {
server.close();
}
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:26,代码来源:Rx2Test.java
示例12: onNext
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
@Override
public void onNext(Buffer buffer) {
Response response = new ResponseParser().apply(buffer.getDelegate().getBytes());
if (ResponseType.PING.equals(response.getType())) {
String gameVersion = ((ResponsePing) response).getGameVersion();
if (!API_VERSION.equals(gameVersion)) {
log.warn("Ocraft uses sc2api in version {}. The game server uses {}.", API_VERSION, gameVersion);
}
cancel();
onConnectionVerified.run();
}
}
开发者ID:ocraft,项目名称:ocraft-s2client,代码行数:13,代码来源:Ping.java
示例13: toObserver
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
/**
* Utility method to report the completion/failure from a Single to a Routing Context.
*
* @param rc the routing context
* @return the single observer to pass to {@link Single#subscribe()}
*/
public static SingleObserver<Buffer> toObserver(RoutingContext rc) {
return new SingleObserver<Buffer>() {
public void onSubscribe(@NonNull Disposable d) {
}
public void onSuccess(@NonNull Buffer payload) {
rc.response().end(payload);
}
public void onError(Throwable error) {
rc.fail(error);
}
};
}
开发者ID:cescoffier,项目名称:vertx-kubernetes-workshop,代码行数:21,代码来源:Helpers.java
示例14: delegateWithCircuitBreaker
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
private void delegateWithCircuitBreaker(RoutingContext rc) {
HttpEndpoint.rxGetWebClient(discovery, svc -> svc.getName().equals("currency-3rdparty-service"))
.flatMap(client ->
// TODO
// Use the circuit breaker (circuit) to call the service. Use the rxExecuteCommandWithFallback` method.
// This methods takes 2 parameters: the first one if a function taking a `Future` as parameter and
// needs to report the success or failure on this future. The second method is a function providing
// the fallback result. You must provide a JSON object as response. For the fallback use:
// new JsonObject()
// .put("amount", rc.getBodyAsJson().getDouble("amount"))
// .put("currency", "USD"))
// In the first function, use the given client, emit a POST request on / containing the incoming
// payload (rc.getBodyAsJson()). Extract the response payload as JSON (bodyAsJsonObject). Don't
// forget to subscribe (you can use subscribe(toObserver(fut)). You can have a look to the `delegate`
// method as example.
// -----
circuit.rxExecuteCommandWithFallback(
fut ->
client.post("/").rxSendJsonObject(rc.getBodyAsJson())
.map(HttpResponse::bodyAsJsonObject)
.subscribe(toObserver(fut)),
err -> new JsonObject()
.put("amount", rc.getBodyAsJson().getDouble("amount"))
.put("currency", "USD")))
// ----
.map(JsonObject::toBuffer)
.map(Buffer::new)
.subscribe(toObserver(rc));
}
开发者ID:cescoffier,项目名称:vertx-kubernetes-workshop,代码行数:33,代码来源:CurrencyServiceProxy.java
示例15: processResponse
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
private Observable<ClientResponse> processResponse(final HttpClientResponse response) {
return Observable.just(Buffer.buffer())
.mergeWith(response.toObservable())
.reduce(Buffer::appendBuffer)
.toObservable()
.map(buffer -> toResponse(buffer, response));
}
开发者ID:Cognifide,项目名称:knotx,代码行数:8,代码来源:HttpRepositoryConnectorProxyImpl.java
示例16: toResponse
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
private ClientResponse toResponse(Buffer buffer, final HttpClientResponse httpResponse) {
if (httpResponse.statusCode() >= 300 && httpResponse.statusCode() < 400) { //redirect responses
LOGGER.info("Repository 3xx response: {}, Headers[{}]", httpResponse.statusCode(),
DataObjectsUtil.toString(httpResponse.headers()));
} else if (httpResponse.statusCode() != 200) {
LOGGER.error("Repository error response: {}, Headers[{}]", httpResponse.statusCode(),
DataObjectsUtil.toString(httpResponse.headers()));
}
return new ClientResponse()
.setStatusCode(httpResponse.statusCode())
.setHeaders(httpResponse.headers())
.setBody(buffer.getDelegate());
}
开发者ID:Cognifide,项目名称:knotx,代码行数:16,代码来源:HttpRepositoryConnectorProxyImpl.java
示例17: logResponse
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
private void logResponse(Pair<ClientRequest, ServiceMetadata> request,
HttpResponse<Buffer> resp) {
if (resp.statusCode() >= 400 && resp.statusCode() < 600) {
LOGGER.error("{} {} -> Got response {}, headers[{}]",
logResponseData(request, resp));
} else if (LOGGER.isDebugEnabled()) {
LOGGER.debug("{} {} -> Got response {}, headers[{}]",
logResponseData(request, resp));
}
}
开发者ID:Cognifide,项目名称:knotx,代码行数:11,代码来源:HttpClientFacade.java
示例18: logResponseData
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
private Object[] logResponseData(Pair<ClientRequest, ServiceMetadata> request,
HttpResponse<Buffer> resp) {
Object[] data = {
request.getLeft().getMethod(),
toUrl(request),
resp.statusCode(),
DataObjectsUtil.toString(resp.headers())};
return data;
}
开发者ID:Cognifide,项目名称:knotx,代码行数:11,代码来源:HttpClientFacade.java
示例19: overrideRequestHeaders
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
private void overrideRequestHeaders(HttpRequest<Buffer> request, ServiceMetadata metadata) {
if (metadata.getAdditionalHeaders().isPresent()) {
metadata.getAdditionalHeaders().get().forEach(entry -> {
request.putHeader(entry.getKey(), entry.getValue().toString());
});
}
}
开发者ID:Cognifide,项目名称:knotx,代码行数:8,代码来源:HttpClientFacade.java
示例20: updateRequestQueryParams
import io.vertx.reactivex.core.buffer.Buffer; //导入依赖的package包/类
private void updateRequestQueryParams(HttpRequest<Buffer> request, ServiceMetadata metadata) {
if (metadata.getQueryParams().isPresent()) {
metadata.getQueryParams().get().forEach(entry ->
request.addQueryParam(entry.getKey(), entry.getValue().toString())
);
}
}
开发者ID:Cognifide,项目名称:knotx,代码行数:8,代码来源:HttpClientFacade.java
注:本文中的io.vertx.reactivex.core.buffer.Buffer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论