Hi,
I’ve started this topic in the old google forum: https://groups.google.com/g/axonframework/c/t6T4cDPzZ6s/m/0R66GG4tBgAJ
@Steven_van_Beelen: I hope I understand your comment in a right way, so the routing key should just be the application name, to make sure that always this service will get the commands? Sadly this is also not working. I’ve two services running, and when I fire a command on Service A, it still happens that Service B is working on it, although Service A has also the Aggregate to work on the command. But you are right, when Axon Server found his path, he always routes to this Service. (But sadly not the service I like. )
And both services are using the following Routing Strategy:
@Primary
@ConditionalOnProperty(prefix = "esp.axon.custom-routing", name = "enabled", havingValue = "true", matchIfMissing = true)
@Component
@Slf4j
public class EspRoutingStrategy extends AnnotationRoutingStrategy {
private final String routingPrefix;
public EspRoutingStrategy(@Value("${esp.axon.custom-routing.cluster.name:}") final String clusterName,
@Value("${spring.application.name:}") final String applicationName) {
if(!clusterName.isEmpty()) {
routingPrefix = replaceBlanks(clusterName);
} else if(!applicationName.isEmpty()){
routingPrefix = replaceBlanks(applicationName);
} else {
throw new IllegalStateException("At least spring.application.name hast to be configured!");
}
log.info("Use EspRoutingStrategy for Axon! RoutingKey: {}", routingPrefix);
}
@Override
public String getRoutingKey(final CommandMessage<?> command) {
//First let axon resolve the key, looks like e.g.: de.edeka.digital.esp.Request#EXAMPLE:2020-09-08:0001
//final String routingKey = super.getRoutingKey(command);
//log.trace("Routing Key from Axon: {}", routingKey);
final String newRoutingKey = routingPrefix;
log.trace("Routing Key with Prefix: {}", newRoutingKey);
return newRoutingKey;
}
protected String replaceBlanks(final String value) {
return value.replaceAll("\\s+","");
}
}
(I extend AnnotationRoutingStrategy, because when I created the post, I thought I need a routing key where I join the app name + the original routing key. So I got something like this: ServiceA#de.edeka.digital.esp.Request#EXAMPLE:2020-09-08:0001
Cheers,
Patrick