SimpleCommandBus Dispatching multiple messages every few minutes

I add an event, all good, see controller below…

I then read every 2 secs from a normal SELECT statement…

The SimpleCommandBus kicks in and dispatches the same command again and again and again…

Controller…

@Path("/lock/{sku}")
public Response lock(@PathParam("sku") String sku, @QueryParam("quantity") Integer quantity, @QueryParam("location") String location, @QueryParam("zone") String zone) {
    LOGGER.info(String.format("Invoking Lock Update API %s", sku));
    commandGateway.send(new GenericCommandMessage<>(new StockItemLockCommand(sku, quantity, new Location(location, zone))));
    return Response.ok("Success").build();
}

Log.....

[http-nio-9093-exec-2] [INFO] [2018-01-25 18:52:03,185] c.d.s.a.e.r.StockEventCassandraRepository: getEvents for Aggregate: 3 SeqNo: 0 BatchSize: 100
[http-nio-9093-exec-3] [INFO] [2018-01-25 18:52:05,186] c.d.s.a.e.c.r.StockEventQueryController: Invoking Events Model API 3
[http-nio-9093-exec-3] [INFO] [2018-01-25 18:52:05,186] c.d.s.a.e.r.StockEventCassandraRepository: getEvents for Aggregate: 3 SeqNo: 0 BatchSize: 100
[http-nio-9093-exec-4] [INFO] [2018-01-25 18:52:07,186] c.d.s.a.e.c.r.StockEventQueryController: Invoking Events Model API 3
[http-nio-9093-exec-4] [INFO] [2018-01-25 18:52:07,186] c.d.s.a.e.r.StockEventCassandraRepository: getEvents for Aggregate: 3 SeqNo: 0 BatchSize: 100
[http-nio-9093-exec-5] [INFO] [2018-01-25 18:52:09,185] c.d.s.a.e.c.r.StockEventQueryController: Invoking Events Model API 3
[http-nio-9093-exec-5] [INFO] [2018-01-25 18:52:09,185] c.d.s.a.e.r.StockEventCassandraRepository: getEvents for Aggregate: 3 SeqNo: 0 BatchSize: 100
[http-nio-9093-exec-7] [INFO] [2018-01-25 18:52:11,186] c.d.s.a.e.c.r.StockEventQueryController: Invoking Events Model API 3
[http-nio-9093-exec-7] [INFO] [2018-01-25 18:52:11,186] c.d.s.a.e.r.StockEventCassandraRepository: getEvents for Aggregate: 3 SeqNo: 0 BatchSize: 100
[http-nio-9093-exec-6] [INFO] [2018-01-25 18:52:13,185] c.d.s.a.e.c.r.StockEventQueryController: Invoking Events Model API 3
[http-nio-9093-exec-6] [INFO] [2018-01-25 18:52:13,185] c.d.s.a.e.r.StockEventCassandraRepository: getEvents for Aggregate: 3 SeqNo: 0 BatchSize: 100

[http-nio-9093-exec-8] [DEBUG] [2018-01-25 18:52:13,379] o.a.c.SimpleCommandBus: Dispatching command [com.xxxxxxx.services.atp.model.command.StockItemLockCommand]
[http-nio-9093-exec-8] [DEBUG] [2018-01-25 18:52:13,379] o.a.m.u.AbstractUnitOfWork: Starting Unit Of Work

Do I need to clear the bus or someting?

Hi Gerard,

not sure what the problem is, exactly. As far as I can see, the logs are polling with 2 secs interval, and after a couple of seconds a command is dispatched.

There is no clearing or anything necessary (or even possible) on the Command Bus.

Cheers,

Allard

Hi Allard,
I really need you help mate.

I dispatch a command and it says completed successfully. The record is in the database.

I then leave the process running with no activity. Every 2 minutes the same record or batch of records get re-submitted.

2018-01-26 12:31:19
2018-01-26 12:33:19
2018-01-26 12:35:19
2018-01-26 12:37:19

Every 2 minutes …

The log starts …SimpleCommandBus: Dispatching command [… ]

AbstractUnitOfWork: Starting Unit Of Work

Notifying handlers for phase STARTED

Handling StockItemLockCommand …

Adding handler com.debenhams.services.atp.engine.handlers
Adding handler or CLEANUP, ROLLBACK, PREPARE_COMMIT

AbstractUnitOfWork: Committing Unit Of Work

AbstractUnitOfWork: Starting Unit Of Work

StockItemCommandHandler: Commiting StockItemLock

LoggingCallBackAxon: Command executed successfully: com.debenhams.services.atp.model.command.

The command is
commandBus.dispatch(message, new LoggingCallBackAxon());

The configuration is

@Bean
public CommandBus commandBus() {
    LOGGER.info("Running Command Configration ...");
    SimpleCommandBus simpleCommandBus =  new SimpleCommandBus();
    //simpleCommandBus.setRollbackConfiguration(RollbackConfigurationType.NEVER);
    return simpleCommandBus;

    //commandBus = new DisruptorCommandBus(eventStore());
    //commandBus = new AsynchronousCommandBus();
}

@Bean
public CommandGateway commandGateway() {
    LOGGER.info("Running Command Gateway Configration ...");
    return new DefaultCommandGateway(commandBus());
}


There are no schedulers running, what is making this submit and re-submit again...every 2 minutes?

Version 3.0.7

Help!

Regards,
Gerry.

Hi Gerry,

I’m pretty sure it isn’t Axon, but it should be fairly simple to find out. Just log a stracktrace, some class near the bottom is your culprit.

Cheers,

Allard

Thanks Allard,

Tell us this, how best to see the unit of work outcome after … how do I best hook command dispatchers or hooks into the DefaultUnitOfwork?

I’m doing this at the moment inside the handler…trying to see if a rollback is happening and it’s re-scheduling…I notice there is no re-schedule on the simplecommandbus, which is good.

UnitOfWork<?> root = CurrentUnitOfWork.get().root();
root.onCommit(x -> LOGGER.info("Commiting StockItemLock"));
root.onRollback( x->  LOGGER.info("Rolling Back StockItemLock"));
root.onCleanup( x->LOGGER.info("Cleaning up StockItemLock" +  x.getExecutionResult().toString()));
root.onPrepareCommit( x-> LOGGER.info("Prepare up StockItemLock"));

I've also hooked into the callback but there is no unit of work there...its done at this point

Hi Gerry,

the only place where retrys could be done are in the CommandGateway, if you have configured a retry scheduler. Other than that, there is nothing in Axon that will trigger an action automatically.

My guess is that your best shot at getting to the source of this, is using a thread dump (or stacktrace).

Cheers,

Allard