mvn io.quarkus:quarkus-maven-plugin:2.3.1.Final:create \
-DprojectGroupId=my-groupId \
-DprojectArtifactId=my-artifactId \
-DprojectVersion=my-version \
-DclassName="org.my.group.MyResource" \
-Dextensions="resteasy-jsonb" \
-DbuildTool=gradle
Option 1
@Singletion
public class SomeBean {
void onStart(@Observes StartupEvent ev) {
}
}
Option 2
@Startup
@Singletion
public class SomeBean {
@PostConstruct
void onStart() {
}
}
public void close(@Observes ShutdownEvent event) throws Exception {
this.consumerFactory.close();
}
CDI.current().select(clazz).get()
quarkus.log.level=INFO
quarkus.log.category."io.agroal".level=TRACE
quarkus.log.category."org.apache.http.client.protocol.ResponseProcessCookies".level=ERROR
quarkus.log.console.format=%d{HH:mm:ss.SSS} [%15.-15t] %-3.3p %i %0.-35C m=%M:%L %m%n
%prod.quarkus.log.console.format=%d{yyyy-MM-dd HH:mm:ss.SSS} [%15.-15t] %-3.3p %i %0.-35C m=%M:%L %m%n
Variável de ambiente `QUARKUS_PROFILE` ou system property `quarkus.profile`
System.setProperty("quarkus.http.port", String.valueOf(config.getWebServerPort()));
System.setProperty("quarkus.log.level", config.getLogLevel().name());
System.setProperty("quarkus.log.console.enable", "false");
System.setProperty("quarkus.log.file.enable", "false");
http://heidloff.net/article/reactive-messaging-examples-quarkus/
https://stackoverflow.com/a/60008991/2979435
https://github.com/smallrye/smallrye-reactive-messaging/issues/400
https://quarkus.io/guides/kafka#imperative-usage
https://vertx.io/docs/vertx-kafka-client/java/
Variável de ambiente QUARKUS_PROFILE
ou system property quarkus.profile
Forma 1
ConfigUtils
.getProfiles()
.contains("test")
Forma 2
ProfileManager.getActiveProfile();
testImplementation("io.quarkus:quarkus-junit5-mockito")
@QuarkusTest
class SolverSystemTest {
@InjectMock(convertScopes = true)
DockerRepository dockerRepository;
....
@InjectMock
SteamAPI steamAPI;
@Test
void test(){
doReturn("").when(mock).someCall();
....
}
@Inject
SteamAPI steamAPI;
@BeforeAll
static void beforeAll(){
final var mock = mock(SteamAPI.class);
doReturn("").when(mock).someCall(); // os mocks tem que ser feitos aqui nessa abordagem
QuarkusMock.installMockForType(, SteamAPI.class);
}
@GET
@RolesAllowed("user")
@Path("/me")
@Produces(MediaType.TEXT_PLAIN)
public String me() {
@GET
public boolean me(@Context SecurityContext securityContext) {
return securityContext.isInRole("admin");
}
ou
import io.quarkus.security.identity.SecurityIdentity;
@Path("/api/users")
public class UserResource {
@Inject
SecurityIdentity securityIdentity;
@GET
public String me() {
return securityIdentity.getPrincipal().getName();
}
.....
@Path("/api/public")
public class PublicResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String publicResource(@Context HttpRequest r) {
https://github.com/quarkusio/quarkus/issues/22101
CDI.current().select(SecurityIdentity.class).get()
Arc.container().instance(clazz).get()
package com.acme;
import io.quarkus.runtime.annotations.QuarkusMain;
import io.quarkus.runtime.Quarkus;
@QuarkusMain
public class Main {
public static void main(String ... args) {
System.out.println("Running main method");
Quarkus.run(args);
}
}
@Produces
ProcessDAO processDAO() {
return this.factory.processDao();
}
import javax.enterprise.inject.Instance;
....
@Inject
public ServerStarter(Instance<Solver> solvers, SimpleServer server) {
this.solvers = Solvers.sorted(Instances.toSet(solvers));
}
....
public static <T> Set<T> toSet(Instance<T> instance) {
return instance
.stream()
.collect(Collectors.toSet())
;
}
@DefaultBean
public class DockerRepositoryDefault implements DockerRepository {
....
}
Tambem funciona para Beans definidos em métodos
O Quarkus sozinho vai serializer pra voce usando jackson, também é possivel setar o seu próprio ObjectMapper
@QuarkusIntegrationTest
@QuarkusIntegrationTest
class SolverSystemIT {
@Test
void mustDeserializeNetworkVO(){
.....
./gradlew clean build testNative -i
# nao testei
quarkus.package.runner-suffix=
# vai tirar a versão do nome, ficando apenas como especificado
quarkus.package.output-name=dns-proxy-server
# vai tirar o suffix "runner", tambem pode ser passado um valor customizado
quarkus.package.add-runner-suffix=false
# vai gerar o uber jar e native image binary no diretorio build/artifacts ao inves de build
quarkus.package.output-directory=artifacts
Mais detailhes em
# https://github.com/quarkusio/quarkus/issues/2931
# quarkus-core-deployment-2.16.0.Final.jar!/META-INF/quarkus-javadoc.properties
./gradlew build -Dquarkus.package.type=native -i -x check -Dquarkus.native.additional-build-args="--native-image-info","--verbose"
quarkus commands, quarkus examples