Closed diogocarleto closed 9 months ago
/cc @gwenneg
Hi @diogocarleto. There are two approaches to solve that issue:
▶️ Approach 1: declare the method that consumes the event as blocking:
This is simpler if you're not familiar with reactive code.
@ConsumeEvent(value = HELLO_WITH_CACHE, blocking = true) // You can do it with this @ConsumeEvent field
public void consumeHello(String value) {
// Same body as before
}
or
@ConsumeEvent(HELLO_WITH_CACHE)
@io.smallrye.common.annotation.Blocking // Or do it with this annotation, the outcome will be identical
public void consumeHello(String value) {
// Same body as before
}
should work.
▶️ Approach 2: make the entire code reactive:
@ConsumeEvent(HELLO_WITH_CACHE)
public Uni<Void> consumeHello(String value) {
System.out.println(value + " incoming");
// Quick and dirty untested code, the real code would probably not look like that.
return cachedList()
.onItem().invoke(list -> {
String s1 = list.stream()
.filter(s -> s.equals("i_1000"))
.findFirst().get();
System.out.println(s1);
}).replaceWithVoid();
}
@CacheResult(cacheName = "myCachedList")
public Uni<List<String>> cachedList() { // quarkus-cache will run in a non-blocking way because the method returns Uni
return Uni.createFrom().item(() -> {
return IntStream.range(0, 10000)
.mapToObj(i -> "i_"+i)
.collect(Collectors.toList());
});
}
This should also work with CompletionStage
in place of Uni
.
I'll try to update the quarkus-cache
doc soon and add examples about this, thanks for reporting it!
Thanks for your clarification. I can update the documentation also if you want.
Best,
See comment.
Describe the bug
I'm trying to upgrade the Quarkus version from 2.5.3 to 2.9.1, and I'm experiencing a problem with quarkus-vertx + quarkus-cache.
Let me explain.
I created my GreetingService with the following code:
Basically
hello
send a message toconsumeHello
that tries to get some data from another method that has cache, in this casecachedList
. Just after I called this, I receive an exception.Expected behavior
No response
Actual behavior
How to Reproduce?
Just download my reproducer, and run the test
GreetingServiceTest
Output of
uname -a
orver
No response
Output of
java -version
No response
GraalVM version (if different from Java)
No response
Quarkus version or git rev
No response
Build tool (ie. output of
mvnw --version
orgradlew --version
)No response
Additional information
No response