[英]Dynamic Topic Name / Quarkus SmallRye Reactive Messaging Kafka
[英]How to process NonBlocking with Smallrye messaging and reactive http client?
我有以下代碼。
@Incoming("my-topic")
void process(String someEvent) {
String someResponse = assuminglyRealFastReactiveClientCall();
}
上面的代碼拋出了一個阻塞線程異常。 使用@Blocking
更正。
@Incoming("my-topic")
@Blocking
void process(String someEvent) {
String someResponse = assuminglyRealFastReactiveClientCall();
}
如果我將String assuminglyRealFastReactiveClientCall()
切換到Uni<String> assuminglyRealFastReactiveClientCall()
我猜消費者方法必須切換到手動確認策略,並且需要根據訂閱結果確認/確認消息,所以呢?
@Incoming("my-topic")
void process(Message<String> someEvent) {
assuminglyRealFastReactiveClientCall()
.subscribe().with(s -> {
System.out.println("Response: " + s);
event.ack();
}, t -> event.nack(t));
}
@Incoming("my-topic")
Uni<Void> process(Message<String> someEvent) {
return assuminglyRealFastReactiveClientCall()
.invoke(this::handleResponse)
.chain(response -> Uni.createFrom().completionStage(someEvent.ack()));
}
private void handleResponse(String response) {
// Do something with the response
}
Smallrye 反應式消息傳遞文檔中的消費消息段落有更多示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.