-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed tracing of outgoing messages (#243)
* Fixed tracing outgoing messages * Bumped io.nats:jnats from 2.20.4 to 2.20.5
- Loading branch information
Showing
74 changed files
with
1,096 additions
and
900 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
release: | ||
current-version: "3.17.1" | ||
current-version: "3.17.3" | ||
next-version: "3.18.0-SNAPSHOT" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...rc/test/java/io/quarkiverse/reactive/messaging/nats/jetstream/test/DataCollectorBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.quarkiverse.reactive.messaging.nats.jetstream.test; | ||
|
||
import java.util.Optional; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import org.eclipse.microprofile.reactive.messaging.Incoming; | ||
import org.eclipse.microprofile.reactive.messaging.Message; | ||
import org.jboss.logging.Logger; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
|
||
@ApplicationScoped | ||
public class DataCollectorBean implements MessageConsumer<Data> { | ||
private final static Logger logger = Logger.getLogger(DataCollectorBean.class); | ||
|
||
private final AtomicReference<Data> lastData = new AtomicReference<>(); | ||
|
||
@Incoming("data-collector") | ||
public Uni<Void> data(Message<Data> message) { | ||
return Uni.createFrom().item(message) | ||
.onItem().invoke(m -> logger.infof("Received message: %s", message)) | ||
.onItem().transformToUni(this::setLast) | ||
.onItem().transformToUni(this::acknowledge) | ||
.onFailure().recoverWithUni(throwable -> notAcknowledge(message, throwable)); | ||
} | ||
|
||
private Uni<Message<Data>> setLast(Message<Data> message) { | ||
return Uni.createFrom().item(() -> { | ||
lastData.set(message.getPayload()); | ||
return message; | ||
}); | ||
} | ||
|
||
public Optional<Data> getLast() { | ||
return Optional.ofNullable(lastData.get()); | ||
} | ||
|
||
} |
47 changes: 28 additions & 19 deletions
47
...rc/test/java/io/quarkiverse/reactive/messaging/nats/jetstream/test/DataConsumingBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,49 @@ | ||
package io.quarkiverse.reactive.messaging.nats.jetstream.test; | ||
|
||
import java.util.Optional; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import org.eclipse.microprofile.reactive.messaging.Channel; | ||
import org.eclipse.microprofile.reactive.messaging.Emitter; | ||
import org.eclipse.microprofile.reactive.messaging.Incoming; | ||
import org.eclipse.microprofile.reactive.messaging.Message; | ||
import org.jboss.logging.Logger; | ||
|
||
import io.quarkiverse.reactive.messaging.nats.jetstream.JetStreamIncomingMessageMetadata; | ||
import io.quarkiverse.reactive.messaging.nats.jetstream.client.api.PublishMessageMetadata; | ||
import io.smallrye.mutiny.Uni; | ||
import io.smallrye.reactive.messaging.annotations.Blocking; | ||
import io.smallrye.mutiny.tuples.Tuple2; | ||
|
||
@ApplicationScoped | ||
public class DataConsumingBean { | ||
public class DataConsumingBean implements MessageConsumer<String> { | ||
private final static Logger logger = Logger.getLogger(DataConsumingBean.class); | ||
|
||
private final AtomicReference<Data> lastData = new AtomicReference<>(); | ||
private final Emitter<Data> dataEmitter; | ||
|
||
public DataConsumingBean(@Channel("data-emitter") Emitter<Data> dataEmitter) { | ||
this.dataEmitter = dataEmitter; | ||
} | ||
|
||
@Blocking | ||
@Incoming("data-consumer") | ||
public Uni<Void> data(Message<String> message) { | ||
return Uni.createFrom().item(message) | ||
.onItem().invoke(m -> { | ||
logger.infof("Received message: %s", message); | ||
message.getMetadata(JetStreamIncomingMessageMetadata.class) | ||
.ifPresent(metadata -> lastData.set( | ||
new Data(message.getPayload(), metadata.headers().get("RESOURCE_ID").get(0), | ||
metadata.messageId()))); | ||
}) | ||
.onItem().transformToUni(m -> Uni.createFrom().completionStage(m.ack())) | ||
.onFailure().recoverWithUni(throwable -> Uni.createFrom().completionStage(message.nack(throwable))); | ||
.onItem().invoke(m -> logger.infof("Received message: %s", message)) | ||
.onItem().transformToUni(this::publish) | ||
.onItem().transformToUni(this::acknowledge) | ||
.onFailure().recoverWithUni(throwable -> notAcknowledge(message, throwable)); | ||
} | ||
|
||
public Optional<Data> getLast() { | ||
return Optional.ofNullable(lastData.get()); | ||
private Uni<Message<String>> publish(Message<String> message) { | ||
try { | ||
return Uni.createFrom() | ||
.item(() -> message.getMetadata(PublishMessageMetadata.class) | ||
.map(metadata -> Tuple2.of(metadata.headers().get("RESOURCE_ID").get(0), metadata.messageId())) | ||
.orElse(Tuple2.of(null, null))) | ||
.onItem() | ||
.transformToUni(tuple -> Uni.createFrom() | ||
.completionStage( | ||
dataEmitter.send(new Data(message.getPayload(), tuple.getItem1(), tuple.getItem2())))) | ||
.onItem().transform(ignore -> message); | ||
} catch (Exception e) { | ||
return Uni.createFrom().failure(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
.../src/test/java/io/quarkiverse/reactive/messaging/nats/jetstream/test/MessageConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.quarkiverse.reactive.messaging.nats.jetstream.test; | ||
|
||
import org.eclipse.microprofile.reactive.messaging.Message; | ||
|
||
import io.smallrye.mutiny.Uni; | ||
|
||
public interface MessageConsumer<T> { | ||
|
||
default Uni<Void> acknowledge(Message<T> message) { | ||
return Uni.createFrom().completionStage(message.ack()); | ||
} | ||
|
||
default Uni<Void> notAcknowledge(Message<T> message, Throwable throwable) { | ||
return Uni.createFrom().completionStage(message.nack(throwable)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.