CQRS: Multiple entrypoints for same command process

  softwareengineering

I’m trying to follow the Clean Architecture and CQRS within an application that, let’s say, create a product.

To achieve this, the application has 3 adapters, one for reading a file, another for consuming a Kafka topic and another for receiving REST API requests. These are the three ways that is possible to create a product, since the producers belong to distant teams and it’s not up to me to decide which technology they will use.

The first question: is there a problem with having only one command handler for these 3 adapters? Obviously, they will map each request/event into a common command and then dispatch it.

The second question: where will be the validation? I’m currently doing it on a separate validator class that is called from the command handler, but I’m facing the problem that each request has it’s own fields and conventions, i.e. on Kafka topic the product name field is “product_name” and on CSV file is “ProductName”, and the error message will be based on the command attributes (“the productName is invalid”) since I’m validating only the command object. Because of all of these differences it’s being hard to standardize callback/responses to each product producer.

How would you handle this situation?

Thanks a lot in advance!

New contributor

Vithor Escames is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT