Quarkus tips&tricks

Injecting @ApplicationScope implementations of certain class

import jakarta.enterprise.inject.Instance

@ApplicationScoped
class ClassToInjectInto {
  private lateinit var instances : Instance<WebSocketMessageHandler> 
}

Returning Completion Stage as a Result

@Slf4j
@Tag(name = "\API")
@Path("/api/v1/test")
@ApplicationScoped
@Produces(
    MediaType.APPLICATION_JSON
)
@Consumes(MediaType.APPLICATION_JSON)
class EdgeDeviceRPCResource() {

    
    @GET
    fun stage(): CompletionStage<Response> = CompletableFuture.completedStage(Response.ok().build())
}

Mapping Configuration to Objects

https://quarkus.io/guides/config-mappings

@ConfigMapping(prefix = "server")
public interface Server {
    String host();

    int port();
}

Catching Wildcard Paths with @Path annotation

If there is a need to capture everything after fixed prefix of a path, use this syntax

@Path("/storage/file/{category}/{filePath: .*}")

// Will match
/storage/file/mp3/author/song.mp3

# In this case, filePath will be equal to "author/song.mp3"

Starting application in dev mode with XMX flags

./mvnw quarkus:dev -Djvm.args=-Xmx256M

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *