-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate processing id to insert new dead-letter in order
As events should be handled in order, this means dead-lettered events should include following events in the same sequence. Doing so ensures processing doesn't go awry. To that end, it's beneficial to wrap the SimpleEventHandlerInvoker in a dead-letter aware variant that can validate the contents of the queue for a new event it receives. If it's present, the event should be added. If it's not present, regular handling should proceed. #2021
- Loading branch information
Showing
5 changed files
with
151 additions
and
22 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
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
64 changes: 64 additions & 0 deletions
64
...c/main/java/org/axonframework/eventhandling/deadletter/DeadLetterEventHandlerInvoker.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,64 @@ | ||
/* | ||
* Copyright (c) 2010-2021. Axon Framework | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.axonframework.eventhandling.deadletter; | ||
|
||
import org.axonframework.eventhandling.EventMessage; | ||
import org.axonframework.eventhandling.Segment; | ||
import org.axonframework.eventhandling.SimpleEventHandlerInvoker; | ||
import org.axonframework.messaging.deadletter.DeadLetterQueue; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
|
||
/** | ||
* @author Steven van Beelen | ||
* @since 4.6.0 | ||
*/ | ||
public class DeadLetterEventHandlerInvoker extends SimpleEventHandlerInvoker { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
|
||
private final DeadLetterQueue<EventMessage<?>> queue; | ||
|
||
/** | ||
* Instantiate a {@link SimpleEventHandlerInvoker} based on the fields contained in the {@link Builder}. | ||
* <p> | ||
* Will assert that at least one {@link org.axonframework.eventhandling.EventMessageHandler} is provided, and will | ||
* throw an {@link org.axonframework.common.AxonConfigurationException} if this is not the case. | ||
* | ||
* @param builder the {@link Builder} used to instantiate a {@link SimpleEventHandlerInvoker} instance | ||
*/ | ||
public DeadLetterEventHandlerInvoker(Builder builder) { | ||
super(builder); | ||
this.queue = builder.deadLetterQueue(); | ||
} | ||
|
||
@Override | ||
public void handle(EventMessage<?> message, Segment segment) throws Exception { | ||
String sequenceIdentifier = super.sequenceIdentifier(message).toString(); | ||
if (queue.addIfPresent(sequenceIdentifier, () -> new GenericEventDeadLetter(sequenceIdentifier, message))) { | ||
logger.info("Event [{}] is added to the dead-letter queue since its processing id [{}] was already present.", | ||
message, sequenceIdentifier); | ||
} else { | ||
logger.debug("Event [{}] with processing id [{}] is not present in the dead-letter queue present." | ||
+ "Handle operation is delegate to the parent.", | ||
message, sequenceIdentifier); | ||
super.handle(message, segment); | ||
} | ||
} | ||
} |
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