Custom Topic Ordering
A common customization to the LOAD
operation is to enforce the order in which certain topics are processed.
We can achieve this by creating a List of Sets of topics from the incoming request and then process them in the desired order.
This can be done by overriding the existing LOAD
operation.
Configuration
@Configuration
public class CustomOperationsConfig {
@Bean
public DlcLoadOperation customLoadOperation(DlcLoadOperationsService dlcLoadOperationsService, INamedEntityResolverService namedEntityResolverService, DlcDescription dlcDescription) {
return new CustomLoadOperation(dlcLoadOperationsService, namedEntityResolverService, dlcDescription);
}
}
Alternatively you can annotate the CustomLoadOperation
class with @Component
and let Spring manage the bean
creation.
Custom Operation
@Component
public class CustomLoadOperation extends DlcLoadOperation {
public CustomLoadOperation(
DlcLoadOperationsService dlcLoadOperationsService,
NamedEntityResolverService namedEntityResolverService,
DlcDescription dlcDescription
) {
super(dlcLoadOperationsService, namedEntityResolverService, dlcDescription);
}
@Override
public DlcLoadResponse process(DlcLoadRequest request) {
Set<String> topics = dlcLoadOperationsService.resolveAliases(request);
List<Set<String>> organizedTopics = organizeTopics(incomingTopics);
var responses = organizedTopics.stream()
.filter(Predicate.not(Set::isEmpty))
.map(topicsList -> dlcLoadOperationsService.load(topicsList, request.topicOverrides(), request.scope(), request.sourceName(), request.sourceType()))
.toList();
return dlcLoadOperationsService.mergeResponses(responses);
}
List<Set<String>> organizeTopics(Set<String> topics) {
// Custom logic to order topics
}
}