How to transform external requests into commands?

177 views
Skip to first unread message

joost.va...@gmail.com

unread,
May 28, 2015, 5:10:08 PM5/28/15
to ddd...@googlegroups.com
Hi all,

I'am reading a lot into CQRS and DDD but cant exactly pinpoint what I should/could use to transform external requests (from a existing legacay application) into a domain command.

Take for example a traffic light system. It would be nice if our system received an external message like "ChangedToRedEvent". This would then be a command for our system on which to act and execute some business logic which results in a new Event on our side. Instead of receiving a change in state we receive the complete denormalized current state of the traffic light, let's say => "Red=false, Yellow=false, Green=true"


If you wanted to build a CQRS application, where do you transform the incoming "Red=false, Yellow=false, Green=true" into ChangedToRedEvent??



My current guess is that i need to create some sort of Domain Service which access the read side which should offer the last received state (probably in the same format) to determine what is changed. That way the domain service could derive (create) the command from the external messages. 

So an CQRS/event sourced application flow would then be something like:

1. Receive message on incoming adapter
2. Domain service queries read side for any relevant information to derive a command.
3. Handle the command based and create an event based on the domain rules
4. Post the event
5. Handle the event  (Update read side projections, etc...)

Any thoughts?

Joost

joost.va...@gmail.com

unread,
May 28, 2015, 5:12:42 PM5/28/15
to ddd...@googlegroups.com
Correction: 
If you wanted to build a CQRS application, where do you transform the incoming "Red=false, Yellow=false, Green=true" into ChangedToRedCommand??

Op donderdag 28 mei 2015 23:10:08 UTC+2 schreef joost.va...@gmail.com:

Sam Striano

unread,
Aug 21, 2015, 1:17:47 PM8/21/15
to DDD/CQRS
I would like to know if you ever figured this question out.
Thanks!

Fredrik Lejdholt

unread,
Aug 22, 2015, 7:13:58 AM8/22/15
to DDD/CQRS
Hi

I would use a "Anticorruption layer" from DDD, as a adapter to your domain, which is not a direct part of your domain. 
This Anticorruption layer can be a self hosted service that knows how to transform your external state in to commands which it then will execute through your domain api.
This service can use existing read models or create its own from domain events and the external state.

Otherwise your application flow seems right.
Reply all
Reply to author
Forward
0 new messages