Can I have some help understanding Uni transforms? #28368
-
I have a consumer like this which awaits a Vertx Future then returns the result as a @ConsumeEvent("bus01F")
public Uni<MessageOutBean> bus01F(MessagePacket messagePacket) {
// Relay the request as an incoming message and await the future response
Future<MessageOutBean> futureResponse = this.processIncomingMessagePacket(messagePacket, redisJsonDatasource);
// Turn the completed future (when it IS completed) into the Uni
return Uni.createFrom().completionStage(futureResponse.toCompletionStage());
} I understand I might be able to refactor my code to use a Uni instead of a Future, but that is for a future exploration (no pun intended). Here is an abbreviated version of the request code method, which works. protected Uni<DataGraph> createAnEdge(String c_mkey, String p_mkey) {
Promise<DataGraph> promise = Promise.promise();
final Future<DataGraph> future = promise.future();
// Build the request message packet bean
MessagePacket messagePacket = new MessagePacket(c_mkey, p_mkey);
// Make the request
Uni<Message<MessageOutBean>> response = eventBus.request("bus01F", messagePacket);
// Extract the DataGraph
response.subscribe().with(
messageOutBean -> {
promise.complete(this.getDataGraphFromMessage(messageOutBean));
},
failure -> {
promise.fail("create edge failure=" + failure);
});
// Return the Uni<DataGraph> from the future
return Uni.createFrom().completionStage(future.toCompletionStage());
} The request is being handled correctly and is returning the correct The So, I am receiving back a My question is: I think there might be a simpler way to return a This is not critical since I have a working solution but I am interested in better understanding Mutiny. Thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I am not a mutiny expert, but hopefuly I can help a bit. I think you can try do something like the code below. Obviously I have not tested since I do not have your code. I also know nothing about eventBus and such.
You can add a |
Beta Was this translation helpful? Give feedback.
I am not a mutiny expert, but hopefuly I can help a bit.
I think you can try do something like the code below. Obviously I have not tested since I do not have your code. I also know nothing about eventBus and such.
You can add a
onFailure()
then do whatever you need in the failure case.