Skip to main content

Posts

Showing posts with the label Quarkus

How to use Groovy + GraalVM + Quarkus together?

If you are one among those who like Groovy for its simplicity and tight integration with Java (and not for its dynamic capabilities) and wondered how to write Groovy code in a Quarkus application and compile it to native using GraalVM? I have you covered. You dont have to look anywhere else. Scope groovy code as part of quarkus application statically compilable groovy code with no dynamic feature compile the final application to native code using graalvm Code example can be found here . Steps Create a quarkus application as outlined here Add your groovy class under src/main/java Annotate your groovy class with @groovy.transform. CompileStatic create a file called application.properies under src/main/resources folder with the following content. quarkus.native.additional-build-args=\ --allow-incomplete-classpath, \ --report-unsupported-elements-at-runtime, \ --initialize-at-build-time, \ --initialize-at-run-time=org.codehaus.groovy.control.XStreamUtils\\,groov...

How to retry a method call in Spring or Quarkus?

Have you ever come across a situation where you wanted to retry a method invocation automatically? Let's say you are calling a stock ticker service for a given stock and get a transient error. Since it is a transient error, you will try again and it may work in second attempt. But what if it doesn't? Well, you will try third time. But how many times can you try like that? More importantly after how much time will you retry? Imagine if you have a handful of methods like this. Your code will become convoluted with retry logic. Is there a better way? Well, if you are using spring/spring boot, you are in luck. Here is how you can do that using spring. Let's write our business service as follows. import java.time.LocalDateTime; import java.util.concurrent.CompletableFuture; import lombok.extern.slf4j.Slf4j; import org.springframework.retry.annotation.Backoff; import org.springframework.retry.annotation.Retryable; import org.springframework.scheduling.annotation.Async; import...