Hi,
I am trying to run a sample application on my local machine.
If I run this code in an Action to create a Product, it is working fine
private Effect<String> onOneCommandInToManyCommandsOut(CreateProductsCommand createProductCommand) {
Product product = createProductCommand.products().get(0);
ProductEntity.CreateProductCommand cmd = toCommand(product);
return effects().forward(callFor(cmd));
}
private DeferredCall<Any, String> callFor(ProductEntity.CreateProductCommand command) {
log.info("Trying to Create Product: "+ command.skuId());
return componentClient.forEventSourcedEntity(command.skuId())
.call(ProductEntity::create)
.params(command);
}
However, If I use asyncReply + execute() the API requests just times out without any error on the console
private Effect<String> onOneCommandInToManyCommandsOut(CreateProductsCommand createProductCommand) {
Product product = createProductCommand.products().get(0);
ProductEntity.CreateProductCommand cmd = toCommand(product);
CompletionStage<String> reply = callFor(cmd);
return effects().asyncReply(reply);
}
private Effect<String> onOneCommandInToManyCommandsOut(CreateProductsCommand createProductCommand) {
log.info("Trying to Create Product: "+ command.skuId());
return componentClient.forEventSourcedEntity(command.skuId())
.call(ProductEntity::create)
.params(command);
.execute();
}
My use-case: PUT a list of products the asynchronously creates Products and responds backs with “OK” when done.
Helper Methods:
private ProductEntity.CreateProductCommand toCommand(Product item) {
log.info("Command: {}", item);
return new ProductEntity.CreateProductCommand(
item.skuId(),
item.skuName(),
item.description(),
item.msrp());
}
public Effect<String> create(@RequestBody CreateProductCommand command) {
log.info("EntityId: {}\n_State: {}\n_Command: {}", entityId, currentState(), command);
return Validator.<Effect<String>>start()
.isEmpty(command.skuId(), "Cannot create Product without skuId")
.onError(errorMessage -> effects().error(errorMessage, Status.Code.INVALID_ARGUMENT))
.onSuccess(() -> effects()
.emitEvent(currentState().eventFor(command))
.thenReply(__ -> "OK"));
}