Skip to content

Aaptor Design

Reid Spencer edited this page Mar 11, 2022 · 1 revision

Adapter language definition for RIDDL.

Objective

Identify real-world implementation to inform the design of RIDDL adapter language.

Use Cases

Event translation

An event stream that needs to be transformed and adapted to existing domain language. This is

Topic routing

A single data stream needs to be re-routed to new topics in different Kafka/MQ/streams.

Versioning

Translate older versions or schemas of commands into a new bounded context.

Conditionals

If/then/else that can call functions based on incoming data.

Step-by-step

Handling mapping of an event stream in step-by-step functionality, probably defined using conditionals and functions.

Notes

  • Conditionals determine the output of a mapping in an adapter
  • Functions are placeholders that are generated into trait definitions
  • Adapter language should only address data that needs changing
  • In DDD+Reactive world, adapters are using ETL between domains and contexts
  • Conditions can map to functions

User interaction and design

An adapter resembles a consumer with some minor differences. In the future adapters may not always be message driven (there may be edge cases requiring non-message-driven ACLs), therefore we explicitly state event mapping and the message topic of origin.

topic STV is {
  events {
    ItemLoadedToVehicle is { vehicle: Id(Vehicle), item: Id(Item) }
  }
}

adapter EDBAdapter {
  condition ItemIsLate takes (Id(Item)) explained as { “determines if the item is late” }
  transform HandleLateItem is from ItemLoadedToVehicle to EmailNotificationOfLateItem
  transform MultipleItems is from ItemLoadedToVehicle to SomeOtherMessage 

  message mapping from topic STV {
    on ItemLoadedToVehicle {
      when condition ItemIsLate(ItemLoadedToVechicle.item) then {
       publish to topic DistributionItemTopic
       (use|run|execute|do) transform handleLateItem then { publish to NotificationTopic }
     } else {
       publish to DistributionItemTopic
     }
     when condition DistributionItem.ItemIsBig {
       when condition DistributionItem.ItemRequiresAdditionalPayment {
         publish to topic BillingItemTopic
       }
     }
   }
   on MultiItemEvent {
     use transform MultipleItems {
       publish to topic DistributionItemTopic
     }
   }
 }
}

Adapter AST

You can read the above code as the following in the RIDDL AST:

adapter <AdapterRef> {
  message mapping from <TopicRef> {
    <OnClause> {
      <OnClauseStatement>
    }
  }
}

When an OnClauseStatement is broken into then and else clauses:

when <expression="condition ItemIsLate(input)"> (is true) then {

}

#Open Questions

Question

Answer

Date Answered

  • How verbose is existing EDB adapter written for Innovapost?

    • We determined with that semi-verbose is the most user-friendly.
  • In RIDDL world, what is an adapter compared to an adapter in DDD world?

    • We are opinionated that adapters will receive events 1-way via an event stream.
  • How do DDD “services” fit in?

    • TBD

References