本文整理汇总了Java中reactor.core.publisher.Mono.just方法的典型用法代码示例。如果您正苦于以下问题:Java Mono.just方法的具体用法?Java Mono.just怎么用?Java Mono.just使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reactor.core.publisher.Mono
的用法示例。
在下文中一共展示了Mono.just方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addComment
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@PostMapping("/comments")
public Mono<String> addComment(Mono<Comment> newComment) {
if (commentSink != null) {
return newComment
.map(comment -> {
commentSink.next(MessageBuilder
.withPayload(comment)
.setHeader(MessageHeaders.CONTENT_TYPE,
MediaType.APPLICATION_JSON_VALUE)
.build());
return comment;
})
.flatMap(comment -> {
meterRegistry
.counter("comments.produced", "imageId", comment.getImageId())
.increment();
return Mono.just("redirect:/");
});
} else {
return Mono.just("redirect:/");
}
}
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:23,代码来源:CommentController.java
示例2: createPublisher
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Override
public Publisher<Message> createPublisher(long elements) {
ReactorTckGrpc.ReactorTckStub stub = ReactorTckGrpc.newReactorStub(channel);
Mono<Message> request = Mono.just(toMessage((int) elements));
Mono<Message> publisher = stub.oneToOne(request);
return publisher.flux();
}
示例3: update
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<Post> update(Long id, Post post) {
Post updated = data.get(id);
updated.setTitle(post.getTitle());
updated.setContent(post.getContent());
data.put(id, updated);
return Mono.just(updated);
}
示例4: deleteImageShouldWork
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Test
public void deleteImageShouldWork() {
// given
String imageName = "alpha.jpg";
Mono<Image> image = Mono.just(new Image("1", imageName));
given(repository.findByName(any())).willReturn(image);
given(repository.delete((Image) any())).willReturn(Mono.empty());
// when
Mono<Void> done = imageService.deleteImage(imageName);
// then
then(done.block()).isNull();
}
开发者ID:PacktPublishing,项目名称:Learning-Spring-Boot-2.0-Second-Edition,代码行数:15,代码来源:ImageServiceTests.java
示例5: info
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@GetMapping("info")
public Mono<Object> info() {
return Mono.just(singletonMap("token_endpoint", props.getExternalUrl()));
}
示例6: getMonoFromJson
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
private static <T> Mono<T> getMonoFromJson(final String json, final Class<T> type) {
final ObjectMapper objectMapper = new ObjectMapper();
try {
return Mono.just(objectMapper.readValue(json, type));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例7: index
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@GetMapping("/")
public Mono<String> index(Model model) {
model.addAttribute("images",
imageService
.findAllImages()
.map(image -> new HashMap<String, Object>() {{
put("id", image.getId());
put("name", image.getName());
// tag::comments[]
put("comments", commentHelper.getComments(image));
// end::comments[]
}})
);
return Mono.just("index");
}
示例8: oneToMany
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
/**
* Implements a unary -> stream call as {@link Mono} -> {@link Flux}, where the server responds with a
* stream of messages.
*/
public static <TRequest, TResponse> void oneToMany(
TRequest request, StreamObserver<TResponse> responseObserver,
Function<Mono<TRequest>, Flux<TResponse>> delegate) {
try {
Mono<TRequest> rxRequest = Mono.just(request);
Flux<TResponse> rxResponse = Preconditions.checkNotNull(delegate.apply(rxRequest));
rxResponse.subscribe(new ReactivePublisherBackpressureOnReadyHandler<>(
(ServerCallStreamObserver<TResponse>) responseObserver));
} catch (Throwable throwable) {
responseObserver.onError(prepareError(throwable));
}
}
示例9: findById
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<Post> findById(Long id) {
return Mono.just(data.get(id));
}
示例10: save
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<Post> save(Post post) {
Long id = nextId();
Post saved = Post.builder().id(id).title(post.getTitle()).content(post.getContent()).build();
data.put(id, saved);
return Mono.just(saved);
}
示例11: deferred
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@GetMapping("deferred")
public Mono<String> deferred() {
return Mono.just("Jesse");
}
示例12: delete
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<Post> delete(Long id) {
Post deleted = data.get(id);
data.remove(id);
return Mono.just(deleted);
}
示例13: accept
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Override
public Mono<RSocket> accept(ConnectionSetupPayload connectionSetupPayload, RSocket rSocket) {
logger.info("Receiving connection");
return Mono.just(handler);
}
示例14: findByName
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@Override
public Mono<ItemInventory> findByName(String name) {
ItemInventory result = items.get(name);
return result == null ? Mono.empty() : Mono.just(result);
}
示例15: queryCardSet
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
/**
* 根据类型获取指定的卡号组
*
* @param type 卡号组的类型
* @return 特定的卡号组
*/
public Mono<String[]> queryCardSet(CardType type) {
return Mono.just(cardSetOperate.obtainCardSet(type.name()).block().getCardList());
}