Skip to content

Commit

Permalink
Migrate the context propagation quickstart to RESTEasy Reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
cescoffier authored and gsmet committed Mar 9, 2022
1 parent b13185c commit 920ab3d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
6 changes: 1 addition & 5 deletions context-propagation-quickstart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand All @@ -44,10 +44,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import io.smallrye.mutiny.infrastructure.Infrastructure;
import org.eclipse.microprofile.reactive.messaging.Channel;
import org.jboss.resteasy.reactive.RestSseElementType;
import org.jboss.resteasy.reactive.RestStreamElementType;
import org.reactivestreams.Publisher;

import io.smallrye.mutiny.Multi;
Expand All @@ -26,11 +27,14 @@ public class EmitterResource {
@GET
@Path("/prices")
@Produces(MediaType.SERVER_SENT_EVENTS)
@RestSseElementType(MediaType.TEXT_PLAIN)
@RestStreamElementType(MediaType.TEXT_PLAIN)
public Publisher<Double> prices() {
// get the next three prices from the price stream
return Multi.createFrom().publisher(prices)
.select().first(3)
// The items are received from the event loop, so cannot use Hibernate ORM (classic)
// Switch to a worker thread, the transaction will be propagated
.emitOn(Infrastructure.getDefaultExecutor())
.map(price -> {
// store each price before we send them
Price priceEntity = new Price();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package org.acme.context;

import io.smallrye.mutiny.Uni;
import io.smallrye.reactive.messaging.MutinyEmitter;
import org.eclipse.microprofile.reactive.messaging.Channel;
import org.eclipse.microprofile.reactive.messaging.OnOverflow;

import javax.inject.Inject;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

import org.eclipse.microprofile.reactive.messaging.Channel;
import org.eclipse.microprofile.reactive.messaging.Emitter;

@Path("/")
public class PriceResource {

@Inject @Channel("prices") Emitter<Double> emitter;
@Inject @Channel("prices")
MutinyEmitter<Double> emitter;

@POST
public void postAPrice(Price price) {
emitter.send(price.value);
public Uni<Void> postAPrice(Price price) {
if (emitter.hasRequests()) {
return emitter.send(price.value);
} else {
return Uni.createFrom().nullItem();
}
}

}

0 comments on commit 920ab3d

Please sign in to comment.