Skip to content

An issue when use DisruptorCommandBus when have multiple Publisher Thread #325

@thirdson

Description

@thirdson

Look really weird, must be something I configuration incorrect, any advice will be very appriciated..

Aggregate root:

@AggregateRoot public class Portfolio { @AggregateIdentifier private String accountId; private Map<Currency, Cash> cash = new ConcurrentHashMap<>(); }

Create logic:

`
CreateAccountCommand command = new CreateAccountCommand(accountId, id);
try {
commandGateway.send(command, new CommandCallback<CreateAccountCommand, Object>() {
@OverRide
public void onSuccess(CommandMessage<? extends CreateAccountCommand> commandMessage, Object result) {
commandGateway.send(new DepositCashCommand(userId, Cash.asUSD(1000d)));
}

	@Override
	public void onFailure(CommandMessage<? extends CreateAccountCommand> commandMessage, Throwable cause) {
		cause.printStackTrace();
		System.exit(1);
	}
});

} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
`

Event handler side:

`

@eventhandler
public void handleCashDepositedEvent(CashDepositedEvent event)

@eventhandler
public void handleAccountCreatedEvent(AccountCreatedEvent event)

`

Bus:

`
@bean
@Profile("disruptor")
public CommandBus commandBus(@Autowired EventStore es){

DisruptorConfiguration configuration = new DisruptorConfiguration();
configuration.getDispatchInterceptors().add(new BeanValidationInterceptor<>());
configuration
		.setInvokerThreadCount(Runtime.getRuntime().availableProcessors()/2)
		.setPublisherThreadCount(1);  //1 always work ? 1 not work

DisruptorCommandBus cb = new DisruptorCommandBus(es, configuration);
return cb;

}
`

If I test public 10 CreateAccountCommand always be 4~5 account reach EventHandler side..
If I setPublisherThreadCount(1) or switch to simple bus always work correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions