本文整理汇总了Java中reactor.core.publisher.Mono.block方法的典型用法代码示例。如果您正苦于以下问题:Java Mono.block方法的具体用法?Java Mono.block怎么用?Java Mono.block使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reactor.core.publisher.Mono
的用法示例。
在下文中一共展示了Mono.block方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testWithConsumerRecord
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Ignore
@Test
public void testWithConsumerRecord() throws Exception {
KafkaComponent kafka = createComponent();
Mono<List<Object>> receive = Flux.from(kafka.from(TOPIC1, ConsumerRecord.class))
.map(record -> record.value())
.take(2)
.collectList();
Subscriber<ProducerRecord> toTopic = kafka.to(TOPIC1, ProducerRecord.class);
Flux.just(new ProducerRecord<String, String>(TOPIC1, "1", "test"),
new ProducerRecord<String, String>(TOPIC1, "1", "test2"))
.subscribe(toTopic);
List<Object> received = receive.block(Duration.ofSeconds(10));
Assert.assertEquals(2, received.size());
Assert.assertEquals("test", received.get(0));
}
示例2: testWithString
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Ignore
@Test
public void testWithString() throws Exception {
KafkaComponent kafka = createComponent();
Mono<List<String>> receive = Flux.from(kafka.from(TOPIC2, String.class))
.take(2)
.collectList();
Subscriber<ProducerRecord> toTopic = kafka.to(TOPIC2, ProducerRecord.class);
Flux.just(new ProducerRecord<String, String>(TOPIC2, "1", "test"),
new ProducerRecord<String, String>(TOPIC2, "1", "test2"))
.subscribe(toTopic);
List<String> received = receive.block(Duration.ofSeconds(10));
Assert.assertEquals(2, received.size());
Assert.assertEquals("test", received.get(0));
Assert.assertEquals("test2", received.get(1));
}
示例3: main
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
public static void main(String[] args) {
Mono<Integer> mono = Mono.just(2)
.log()
.publishOn(Schedulers.parallel())
.log()
.map(i -> i * 2)
.log()
.publishOn(Schedulers.parallel())
.log()
.map(i -> i - 2)
.log();
mono.block();
}
示例4: findOneShouldReturnNotYetFetchedUrl
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Test
public void findOneShouldReturnNotYetFetchedUrl() {
// when
Mono<Resource> image = imageService.findOneImage("alpha.jpg");
// then
then(image).isNotNull();
Resource resource = image.block();
then(resource.getDescription()).isEqualTo("URL [file:upload-dir/alpha.jpg]");
then(resource.exists()).isFalse();
then(resource.getClass()).isEqualTo(UrlResource.class);
}
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:13,代码来源:ImageServiceTests.java
示例5: doInvoke
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Override
public Object doInvoke(Object argument) {
byte[] data = payloadConverter.write(argument);
Mono monoResult = socket.requestResponse(new PayloadImpl(ByteBuffer.wrap(data), getMetadata()))
.map(payload -> payloadConverter.read(ServiceUtils.toByteArray(payload.getData()), ServiceUtils.getActualType(info.getReturnType())));
if(Mono.class.isAssignableFrom(info.getReturnType().resolve())){
return monoResult;
}
else{
return monoResult.block();
}
}
示例6: synchronizeMono
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Test
public void synchronizeMono() {
Mono<String> tuco = Mono.just("Tuco").subscribeOn(Schedulers.elastic());
String result = tuco.block();
assertThat(result).isEqualTo("Tuco");
}