The Chaos Incarnated: Micro-Quarkus Boot!
MarΓa Arias de Reyna DomΓnguez
@delawen@floss.social
MarΓa Arias de Reyna DomΓnguez
@delawen@floss.social
MarΓa Arias de Reyna DomΓnguez
@delawen@floss.social
Dependency management
Quarkus | Spring Boot | Micronaut |
π | π€ | π΅ |
package com.example;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
@Path("/hello")
public class HelloService {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "Hello from MicroProfile!";
}
}
$ mvn clean quarkus:dev -Pquarkus
$ mvn clean spring-boot:run -Pspring
$ mvn clean mn:run -Pmicronaut
Can I really have an agnostic source code?
Quarkus | Spring Boot | Micronaut |
π | π΅ | π΅ |
I will need a database
com.h2database
h2
runtime
and a volunteer cat
@Entity
public class Cat implements Serializable {
@NotNull
@Column(name = "name", nullable = false)
private String name;
@Id
@GeneratedValue
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
that can be safely placed in a box
@Singleton
public class DatabaseResource {
@PersistenceContext
EntityManager entityManager;
@Transactional
public void addCat(String name) {
Cat cat = new Cat();
cat.setName(name);
entityManager.persist(cat);
}
@Transactional
public List<Cat> getAllCats() {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<Cat> cq = cb.createQuery(Cat.class);
Root<Cat> rootEntry = cq.from(Cat.class);
CriteriaQuery<Cat> all = cq.select(rootEntry);
TypedQuery<Cat> allQuery = entityManager.createQuery(all);
return allQuery.getResultList();
}
and a service to accomodate them
@Path("/db")
public class PersistenceService {
@Inject
DatabaseResource databaseResource;
@GET //For testing purposes
@Path("/cat/{name}")
@Produces(MediaType.TEXT_PLAIN)
@Transactional
public String addCat(@PathParam("name") String name) {
databaseResource.addCat(name);
return "Cat added with name " + name + " via GET.";
}
@POST
@Path("/cat/{name}")
@Produces(MediaType.TEXT_PLAIN)
@Transactional
public String addCatPost(@PathParam("name") String name) {
databaseResource.addCat(name);
return "Cat added with name " + name;
}
@GET
@Path("/cats")
@Produces(MediaType.APPLICATION_JSON)
@Transactional
public List<Cat> getCats() {
return databaseResource.getAllCats();
}
}
Are they going to be mixed up?
Beware: This could be seen as a bug, not a feature!!
Quarkus | Spring Boot | Micronaut |
π΅/π | π΅/π | π/π΅ |
Can I really have an agnostic source code?
Quarkus | Spring Boot | Micronaut |
π | π΅ | π |
Quarkus | Spring Boot | Micronaut | |
Who is your Daddy? | π | π€ | π΅ |
How picky are you (REST)? | π | π΅ | π΅ |
Are my properties clean?* | π/π΅ | π/π΅ | π΅/π |
How picky are you (Persistence)? | π | π΅ | π |