本文整理了Java中reactor.core.publisher.Mono.doOnRequest()
方法的一些代码示例,展示了Mono.doOnRequest()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mono.doOnRequest()
方法的具体详情如下:
包路径:reactor.core.publisher.Mono
类名称:Mono
方法名:doOnRequest
[英]Add behavior triggering a LongConsumer when the Mono receives any request.
Note that non fatal error raised in the callback will not be propagated and will simply trigger Operators#onOperatorError(Throwable,Context).
[中]添加在Mono收到任何请求时触发LongConsumer的行为。
请注意,回调中引发的非致命错误不会传播,只会触发运算符#onOperatorError(Throwable,Context)。
代码示例来源:origin: spring-projects/spring-framework
@Override
public Mono<ClientResponse> exchange(ClientRequest clientRequest) {
Assert.notNull(clientRequest, "ClientRequest must not be null");
HttpMethod httpMethod = clientRequest.method();
URI url = clientRequest.url();
String logPrefix = clientRequest.logPrefix();
return this.connector
.connect(httpMethod, url, httpRequest -> clientRequest.writeTo(httpRequest, this.strategies))
.doOnRequest(n -> logRequest(clientRequest))
.doOnCancel(() -> logger.debug(logPrefix + "Cancel signal (to close connection)"))
.map(httpResponse -> {
logResponse(httpResponse, logPrefix);
return new DefaultClientResponse(httpResponse, this.strategies, logPrefix);
});
}
代码示例来源:origin: reactor/reactor-core
@Test
public void testCommandEmptyPathIsUsedBoilerplate() {
AtomicBoolean wasInvoked = new AtomicBoolean();
AtomicBoolean wasRequested = new AtomicBoolean();
Mono<Void> testFallback = Mono.<Void>empty()
.doOnSubscribe(s -> wasInvoked.set(true))
.doOnRequest(l -> wasRequested.set(true));
processOrFallback(Mono.empty(), testFallback).subscribe();
assertThat(wasInvoked.get()).isTrue();
assertThat(wasRequested.get()).isTrue();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void onMonoDoOnRequest() {
Mono<String> mp = Mono.just("test");
AtomicReference<Long> ref = new AtomicReference<>();
StepVerifier.create(mp.doOnRequest(ref::set), 0)
.thenAwait()
.thenRequest(123)
.expectNext("test")
.verifyComplete();
assertThat(ref.get()).isEqualTo(123);
}
代码示例来源:origin: reactor/reactor-core
@Override
public Mono<T> mono() {
return Mono.from(delegate)
.doOnSubscribe(sub -> incrementAndGet(SUBSCRIBED))
.doOnCancel(() -> incrementAndGet(CANCELLED))
.doOnRequest(l -> incrementAndGet(REQUESTED));
}
代码示例来源:origin: com.aol.cyclops/cyclops-reactor
/**
* @param consumer
* @return
* @see reactor.core.publisher.Mono#doOnRequest(java.util.function.LongConsumer)
*/
public final Mono<T> doOnRequest(LongConsumer consumer) {
return boxed.doOnRequest(consumer);
}
/**
代码示例来源:origin: spring-cloud/spring-cloud-open-service-broker
@RequestMapping(value = {"/v2/catalog", "{platformInstanceId}/v2/catalog"}, method = RequestMethod.GET)
public Mono<Catalog> getCatalog() {
return catalogService.getCatalog()
.doOnRequest(v -> logger.debug("Retrieving catalog"));
}
代码示例来源:origin: spring-cloud/spring-cloud-open-service-broker
@GetMapping(value = {
"/{platformInstanceId}/v2/service_instances/{instanceId}",
"/v2/service_instances/{instanceId}"
})
public Mono<ResponseEntity<GetServiceInstanceResponse>> getServiceInstance(
@PathVariable Map<String, String> pathVariables,
@PathVariable(ServiceBrokerRequest.INSTANCE_ID_PATH_VARIABLE) String serviceInstanceId,
@RequestHeader(value = ServiceBrokerRequest.API_INFO_LOCATION_HEADER, required = false) String apiInfoLocation,
@RequestHeader(value = ServiceBrokerRequest.ORIGINATING_IDENTITY_HEADER, required = false) String originatingIdentityString) {
return Mono.just(GetServiceInstanceRequest.builder()
.serviceInstanceId(serviceInstanceId)
.platformInstanceId(pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE))
.apiInfoLocation(apiInfoLocation)
.originatingIdentity(parseOriginatingIdentity(originatingIdentityString))
.build())
.flatMap(request -> service.getServiceInstance(request)
.doOnRequest(v -> logger.debug("Getting service instance: request={}", request))
.doOnSuccess(response -> logger.debug("Getting service instance succeeded: serviceInstanceId={}, response={}",
serviceInstanceId, response)))
.map(response -> new ResponseEntity<>(response, HttpStatus.OK))
.switchIfEmpty(Mono.just(new ResponseEntity<>(HttpStatus.OK)));
}
代码示例来源:origin: spring-cloud/spring-cloud-open-service-broker
@GetMapping(value = {
"/{platformInstanceId}/v2/service_instances/{instanceId}/service_bindings/{bindingId}",
"/v2/service_instances/{instanceId}/service_bindings/{bindingId}"
})
public Mono<ResponseEntity<GetServiceInstanceBindingResponse>> getServiceInstanceBinding(
@PathVariable Map<String, String> pathVariables,
@PathVariable(ServiceBrokerRequest.INSTANCE_ID_PATH_VARIABLE) String serviceInstanceId,
@PathVariable(ServiceBrokerRequest.BINDING_ID_PATH_VARIABLE) String bindingId,
@RequestHeader(value = ServiceBrokerRequest.API_INFO_LOCATION_HEADER, required = false) String apiInfoLocation,
@RequestHeader(value = ServiceBrokerRequest.ORIGINATING_IDENTITY_HEADER, required = false) String originatingIdentityString) {
return Mono.just(GetServiceInstanceBindingRequest.builder()
.serviceInstanceId(serviceInstanceId)
.bindingId(bindingId)
.platformInstanceId(pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE))
.apiInfoLocation(apiInfoLocation)
.originatingIdentity(parseOriginatingIdentity(originatingIdentityString))
.build())
.flatMap(req -> service.getServiceInstanceBinding(req)
.doOnRequest(v -> logger.debug("Getting a service instance binding: request={}", req))
.doOnSuccess(response -> logger.debug("Getting a service instance binding succeeded: bindingId={}", bindingId)))
.map(response -> new ResponseEntity<>(response, HttpStatus.OK))
.switchIfEmpty(Mono.just(new ResponseEntity<>(HttpStatus.OK)));
}
代码示例来源:origin: spring-cloud/spring-cloud-open-service-broker
.cast(CreateServiceInstanceBindingRequest.class)
.flatMap(req -> service.createServiceInstanceBinding(req)
.doOnRequest(v -> logger.debug("Creating a service instance binding: request={}", req))
.doOnSuccess(response -> logger.debug("Creating a service instance binding succeeded: serviceInstanceId={}, bindingId={}, response={}",
serviceInstanceId, bindingId, response)))
代码示例来源:origin: spring-cloud/spring-cloud-open-service-broker
.cast(CreateServiceInstanceRequest.class)
.flatMap(req -> service.createServiceInstance(req)
.doOnRequest(v -> logger.debug("Creating a service instance: request={}", req))
.doOnSuccess(response ->
logger.debug("Creating a service instance succeeded: serviceInstanceId={}, response={}",
代码示例来源:origin: spring-cloud/spring-cloud-open-service-broker
.cast(UpdateServiceInstanceRequest.class)
.flatMap(req -> service.updateServiceInstance(req)
.doOnRequest(v -> logger.debug("Updating a service instance: request={}", request))
.doOnSuccess(response -> logger.debug("Updating a service instance succeeded: serviceInstanceId={}, response={}",
serviceInstanceId, response)))
代码示例来源:origin: spring-cloud/spring-cloud-open-service-broker
.build())
.flatMap(request -> service.getLastOperation(request)
.doOnRequest(v -> logger.debug("Getting service instance binding last operation: request={}", request))
.doOnSuccess(aVoid -> logger.debug("Getting service instance binding last operation succeeded: serviceInstanceId={}, bindingId={}",
serviceInstanceId, bindingId))
代码示例来源:origin: spring-cloud/spring-cloud-open-service-broker
.build())
.flatMap(request -> service.getLastOperation(request)
.doOnRequest(v -> logger.debug("Getting service instance last operation: request={}", request))
.doOnSuccess(response -> logger.debug("Getting service instance last operation succeeded: serviceInstanceId={}, response={}",
serviceInstanceId, response))
代码示例来源:origin: spring-cloud/spring-cloud-open-service-broker
.build()))
.flatMap(request -> service.deleteServiceInstance(request)
.doOnRequest(v -> logger.debug("Deleting a service instance: request={}", request))
.doOnSuccess(response -> logger.debug("Deleting a service instance succeeded: serviceInstanceId={}, response={}",
serviceInstanceId, response))
代码示例来源:origin: spring-cloud/spring-cloud-open-service-broker
.build()))
.flatMap(req -> service.deleteServiceInstanceBinding(req)
.doOnRequest(v -> logger.debug("Deleting a service instance binding: request={}", req))
.doOnSuccess(aVoid -> logger.debug("Deleting a service instance binding succeeded: bindingId={}", bindingId))
.doOnError(e -> logger.debug(e.getMessage(), e)))
代码示例来源:origin: io.projectreactor/reactor-test
@Override
public Mono<T> mono() {
return Mono.from(delegate)
.doOnSubscribe(sub -> incrementAndGet(SUBSCRIBED))
.doOnCancel(() -> incrementAndGet(CANCELLED))
.doOnRequest(l -> incrementAndGet(REQUESTED));
}
内容来源于网络,如有侵权,请联系作者删除!