Returning multiple events from command

From the existing post, One command multiple domain events ,
does the current framework support to send multiple events from apply.
And if support is, should we be passing the list object to apply ?

Hi @mnkartik,

The post you shared I believe is about Axon 1.
We are at 4.5.3 as we speak.

Sure, the support is there but not as a list.
If you check the code for the AggregateLifecycle you will notice the apply method returns an ApplyMore instance. Checking the code for this one and you will see it has 2 useful methods: andThenApply and andThen which can be used to “chain” calls.

That’s how I would use send multiple events from the Aggregate.
Of course, there is nothing wrong with calling apply several times as well.

KR,

Sorry for the delayed response.
When multiple events are sent, are they published as a single unit or none if any failure ?

Hi @mnkartik,

Yes, if you send multiple events from a given Aggregate (using the methods mentioned before), they are all part of the single ‘transaction’ which is managed by the UnitOfWork.

You can have different behaviours depending on the type of processor you are using (streaming vs subscribing) but that’s another history. Let me know if you want to know more about it as well.

KR,