In the latest reference manual I read about the MetaDataSequencingPolicy which seems a great way to influence the sequencing policy in a dynamic way.
My plan is to add the key “fullConcurrent” with a boolean value to the metaData of specific events which are allowed to be handled full concurrently, like adding or creating aggregateMembers. Where as updates and deletes should be processed sequential per aggregate.
But the MetaDataSequencingPolicy is not present in the latest version of the framework anymore. What would be the best approach to achieve this?
This is…a surprise to me. After reading your request here, @Franky, I went into the project and couldn’t find it either. The weirdest thing is, I am able to find the pull request introducing the MetaDataSequencingPolicy and the issue describing it.
Based on that, and the fact it is gone, the Git history of the org.axonframework.eventhandling.async folder (to which the MetaDataSequencingPolicy) was introduced should show it’s removal. That is, however, not the case at all.
To be frank, I am stupefied.
At any rate, I reopened the branch from pull request #1930, cherry-picked those changes to master, and made some current-day changes to the file. Hence, the limbo-commits are back in action.
This doesn’t help you right away though, @Franky, as the master branch is pending to become the 4.11.0 release of Axon Framework.
Your best bet for now, is to copy the MetaDataSequencingPolicy from the PR and add it to your project. For your convenience, I have copied the entire class down below:
import org.axonframework.common.AxonConfigurationException;
import org.axonframework.eventhandling.EventMessage;
import javax.annotation.Nonnull;
import static org.axonframework.common.BuilderUtils.assertNonNull;
/**
* A {@link SequencingPolicy} implementation that extracts the sequence identifier from the {@link EventMessage}'s
* {@link org.axonframework.messaging.MetaData}, based on a given {@code metaDataKey}. In the absence of the given
* {@code metaDataKey} on the {@link org.axonframework.messaging.MetaData}, the {@link EventMessage#getIdentifier()} is
* used.
*
* @author Lucas Campos
* @since 4.6.0
*/
public class MetaDataSequencingPolicy implements SequencingPolicy<EventMessage<?>> {
private final String metaDataKey;
/**
* Instantiate a {@link MetaDataSequencingPolicy} based on the fields contained in the
* {@link MetaDataSequencingPolicy.Builder}.
* <p>
* Will assert that the {@code metaDataKey} is not {@code null} and will throw an {@link AxonConfigurationException}
* if this is the case.
*
* @param builder The {@link MetaDataSequencingPolicy.Builder} used to instantiate a
* {@link MetaDataSequencingPolicy} instance.
*/
protected MetaDataSequencingPolicy(Builder builder) {
builder.validate();
this.metaDataKey = builder.metaDataKey;
}
/**
* Instantiate a Builder to be able to create a {@link MetaDataSequencingPolicy}.
* <p>
* The following fields of this builder are <b>hard requirements</b> and as such should be provided:
* <ul>
* <li>The {@code metaDataKey} key to be used as a lookup for the property to be used as the Sequence Policy.</li>
* </ul>
*
* @return A Builder to be able to create a {@link MetaDataSequencingPolicy}.
*/
public static Builder builder() {
return new Builder();
}
@Override
public Object getSequenceIdentifierFor(@Nonnull EventMessage<?> event) {
return event.getMetaData()
.getOrDefault(metaDataKey, event.getIdentifier());
}
/**
* Builder class to instantiate a {@link MetaDataSequencingPolicy}.
* <p>
* The following fields of this builder are <b>hard requirements</b> and as such should be provided:
* <ul>
* <li>The {@code metaDataKey} key to be used as a lookup for the property to be used as the Sequence Policy.</li>
* </ul>
*/
public static class Builder {
private String metaDataKey;
private Builder() {
}
/**
* Defines the metaDataKey key to be used as a lookup for the property to be used as the Sequence Policy.
*
* @param metaDataKey Key to be used as a lookup for the property to be used as the Sequence Policy.
* @return The current Builder instance, for fluent interfacing.
*/
public Builder metaDataKey(String metaDataKey) {
this.metaDataKey = metaDataKey;
return this;
}
/**
* Initializes a {@link MetaDataSequencingPolicy} as specified through this Builder.
*
* @return A {@link MetaDataSequencingPolicy} as specified through this Builder.
*/
public MetaDataSequencingPolicy build() {
return new MetaDataSequencingPolicy(this);
}
protected void validate() {
assertNonNull(metaDataKey, "MetaDataKey value may not be null");
}
}
}
In the mean time I created a CustomMatchingEventsSequencingPolicy for the specific events which are allowed to by run with the FullConcurrencyPolicy, which was quite easy to implement. So no worries there.
Loosing commits indeed is weird, makes you wonder what else is lost? A good reason to verify the PR branches with main I guess.