I am creating a delete command and am getting this error
org.axonframework.axonserver.connector.command.AxonServerRemoteCommandHandlingException: An exception was thrown by the remote message handling component: OUT_OF_RANGE: [AXONIQ-2000] Invalid sequence number 0 for aggregate "ef734cce-fb22-4bb1-a68a-8c8c6c7924e9", expected 1
The request am giving in postman is DELETE -> http://localhost:8081/products
body has a String "ef734cce-fb22-4bb1-a68a-8c8c6c7924e9" and in my backend I have file Controller with :
@DeleteMapping()
public String deleteProduct(@RequestBody String productId1) {
//create the command
DeleteProductCommand deleteProductCommand = new DeleteProductCommand (productId1);
String result = commandGateway.sendAndWait(deleteProductCommand);
return result;
}
@Data
@Builder
public class DeleteProductCommand {
@TargetAggregateIdentifier
private String productId;
public DeleteProductCommand(String productId) {
this.productId = productId;
}
}
@EventSourcingHandler
public void on(ProductDeletedEvent event) {
this.productId = event.getProductId();
}
@EventHandler
public void on(ProductDeletedEvent event) {
productRepository.deleteById(event.getProductId());
}
I was expecting it to delete the said product with the passed id.
But when I pass it directly, it gets deleted, I think the error is in somewhere like the event handler or something. At times am getting the product id as json