当前位置: 首页>>代码示例>>Java>>正文


Java Mono.block方法代码示例

本文整理汇总了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));
}
 
开发者ID:cschneider,项目名称:reactive-components,代码行数:20,代码来源:TestKafka.java

示例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));
}
 
开发者ID:cschneider,项目名称:reactive-components,代码行数:20,代码来源:TestKafka.java

示例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();
}
 
开发者ID:akiraly,项目名称:playing-reactor,代码行数:15,代码来源:Mono1.java

示例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();
	}

}
 
开发者ID:viniciusccarvalho,项目名称:spring-cloud-sockets,代码行数:14,代码来源:RequestOneRemoteHandler.java

示例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");
}
 
开发者ID:mp911de,项目名称:reactive-spring,代码行数:10,代码来源:Step7BlockingAndAsync.java


注:本文中的reactor.core.publisher.Mono.block方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。