External Command Handlers -- command does not contain a routing key

Hi all,

I am trying to create an external command handler called SplitService – I have some commands that need to operate on more than one aggregate. I can explain the details around this if necessary, but I think they don’t matter.

I have read the documentation about External Command Handlers and have configured my command handler like:


public class AxonConfig {

public void configure(Configurer configurer, CommandGateway commandGateway, QueryGateway queryGateway,
EventBus eventBus) {
configurer.registerCommandHandler(ch -> new SplitService(commandGateway, queryGateway, eventBus));



The service in question looks like this:



public class SplitService {

private CommandGateway commandGateway;
private QueryGateway queryGateway;
private EventBus eventBus;

public SplitService(CommandGateway commandGateway, QueryGateway queryGateway, EventBus eventBus) {

this.commandGateway = commandGateway;
this.queryGateway = queryGateway;
this.eventBus = eventBus;

public String handle(SplitPackage command) {

PackageRecord parentPackageRecord;
try {
parentPackageRecord =
queryGateway.query(new PackageRecordByIdQuery(command.getParentPackageId()), PackageRecord.class).get();
catch (InterruptedException | ExecutionException e) {
// TODO: research proper handling for this scenario
throw new RuntimeException(e);

// content id mappings
LinkedHashMap<String, String> newChildContentIdToSplitParentContentId = new LinkedHashMap<>();
String childPackageId = buildAdnStoreChild(parentPackageRecord, command, newChildContentIdToSplitParentContentId);
updateParent(parentPackageRecord, command);

// Publish milestone event…
eventBus.publish(new GenericEventMessage(new PackageSplit(command.getExecutorInfo(),
command.getParentPackageId(), command.getChildPackageId(), newChildContentIdToSplitParentContentId)));

return childPackageId;


  • Store the child package, returning it’s identifier when successful otherwise a RuntimeException is raised.

OK, I figured it out. I added a @RoutingKey annotation to my command:


data class SplitPackage(
val executorInfo: ExecutorInfo,
val parentPackageId: String,
val childPackageId: String,
val childOpCo: OpCo?, // defaults to parent’s OpCo
val parentPackageTypeSpec: PackageTypeSpecification?, // only change parent’s package type spec when provided
val parentWeightDim: WeightDim,
val childWeightDim: WeightDim,
val parentContentIdsToSplit: LinkedHashSet


And I also needed to change the dependency injection strategy to inject the needed dependencies into the @CommandHandler method rather than the service’s constructor. Now it all works very well.