-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
103e1a2
commit 15702ef
Showing
13 changed files
with
190 additions
and
78 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
24 changes: 24 additions & 0 deletions
24
documentation/src/main/java/rabbitmq/inbound/RabbitMQRejectMetadataExample.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,24 @@ | ||
package rabbitmq.inbound; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import org.eclipse.microprofile.reactive.messaging.Incoming; | ||
import org.eclipse.microprofile.reactive.messaging.Message; | ||
import org.eclipse.microprofile.reactive.messaging.Metadata; | ||
|
||
import io.smallrye.reactive.messaging.rabbitmq.RabbitMQRejectMetadata; | ||
|
||
@ApplicationScoped | ||
public class RabbitMQRejectMetadataExample { | ||
|
||
// <code> | ||
@Incoming("in") | ||
public CompletionStage<Void> consume(Message<String> message) { | ||
return message.nack(new Exception("Failed!"), Metadata.of( | ||
new RabbitMQRejectMetadata(true))); | ||
} | ||
// </code> | ||
|
||
} |
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
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
53 changes: 53 additions & 0 deletions
53
...rabbitmq/src/main/java/io/smallrye/reactive/messaging/rabbitmq/fault/RabbitMQRequeue.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,53 @@ | ||
package io.smallrye.reactive.messaging.rabbitmq.fault; | ||
|
||
import static io.smallrye.reactive.messaging.rabbitmq.i18n.RabbitMQLogging.log; | ||
|
||
import java.util.Optional; | ||
import java.util.concurrent.CompletionStage; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import org.eclipse.microprofile.reactive.messaging.Metadata; | ||
|
||
import io.smallrye.common.annotation.Identifier; | ||
import io.smallrye.reactive.messaging.rabbitmq.ConnectionHolder; | ||
import io.smallrye.reactive.messaging.rabbitmq.IncomingRabbitMQMessage; | ||
import io.smallrye.reactive.messaging.rabbitmq.RabbitMQConnector; | ||
import io.smallrye.reactive.messaging.rabbitmq.RabbitMQConnectorIncomingConfiguration; | ||
import io.smallrye.reactive.messaging.rabbitmq.RabbitMQRejectMetadata; | ||
import io.vertx.mutiny.core.Context; | ||
|
||
public class RabbitMQRequeue implements RabbitMQFailureHandler { | ||
private final String channel; | ||
|
||
@ApplicationScoped | ||
@Identifier(Strategy.REQUEUE) | ||
public static class Factory implements RabbitMQFailureHandler.Factory { | ||
|
||
@Override | ||
public RabbitMQFailureHandler create(RabbitMQConnectorIncomingConfiguration config, RabbitMQConnector connector) { | ||
return new RabbitMQRequeue(config.getChannel()); | ||
} | ||
} | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param channel the channel | ||
*/ | ||
public RabbitMQRequeue(String channel) { | ||
this.channel = channel; | ||
} | ||
|
||
@Override | ||
public <V> CompletionStage<Void> handle(IncomingRabbitMQMessage<V> msg, Metadata metadata, Context context, | ||
Throwable reason) { | ||
// We mark the message as requeued and fail. | ||
log.nackedIgnoreMessage(channel); | ||
log.fullIgnoredFailure(reason); | ||
boolean requeue = Optional.ofNullable(metadata) | ||
.flatMap(md -> md.get(RabbitMQRejectMetadata.class)) | ||
.map(RabbitMQRejectMetadata::isRequeue).orElse(true); | ||
return ConnectionHolder.runOnContext(context, msg, m -> m.rejectMessage(reason, requeue)); | ||
} | ||
} |
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.