Dispatching a Command object of type <T>

Hi,

I am using Axon and am trying to update our system to support the processing of generic commands to simplify our code.

I have currently implemented the following pattern -


public class Command<T extends Data> extends StandardCommand {

private T payload;

    public Command(String id, T payload) {
        super(id);
        this.data = data;
    }

}

When I attempt to send an instance of Command along the command gateway (Where T represents the payload object type), the aggregate is not matching the object type to the subscribing class which I have defined within the aggregate. This is resulting in the AggregateNotFound exception being thrown. (The aggregate identifier is specified in the superclass)

Therefore my question is simple, does the CommandGateway object support the subscription of generic message types? If it does, can anyone point me to an example of how this can be achieved please? I wanted to keep this short so I hope I have provided enough detail.

Thanks,
Jordan

Hi Jordan,

Axon definitely supports generic messages.

To be more precise, that’s exactly how Axon deals with Commands, Events and Queries internally.
You can have a look at the CommandMessage, EventMessage and QueryMessage interfaces if you want.

From a usage perspective, if you’d give a CommandMessage to the CommandGateway, Axon will automatically know to pull the wrapped payload (your own Command class) as the payloadType of that message.
The same holds for the QueryGateway and the soon to be released EventGateway.

I hope this helps you out Jordan!

Cheers,
Steven