Error in AggregateLifecycle.apply

In my below command I get this error:

Caused by: java.lang.IllegalStateException: Cannot request current Scope if none is active

public void handle(PHACommand cmd, WebClient webClient, ConfigCommandProperties configCommandProperties) {
    PHAEvent event = new PHAEvent(cmd.externalId, cmd.internalId, cmd.agreementId); + "v1.0/pha")
            .contentType(MediaType.APPLICATION_JSON).bodyValue(event).exchange().subscribe(clientResponse -> {
                if (clientResponse.statusCode().equals(HttpStatus.OK)) {
                    AggregateLifecycle.apply(event); // ERROR
                } else {
                    throw new BankDataSyncException();

Hi @Aymen_Kanzari, is your @CommandHandler method inside an Aggregate?
I would expect to see this error when it’s not the case.

Yes it’s inside the Aggregate.
When i take the line AggregateLifecycle.apply(event); out of webClient, it work fine.

The reason the apply fails is because it’s executed in another thread that invoked the aggregate.
The http call returns asynchronously and uses another thread to handle the response. Axon doesn’t support that (yet).

The solution would be to block for the response. Or better, avoid needing to perform an http call in an aggregate at all.

1 Like