This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
Support for polymorphic ADTs as protocol between two Streamlets #203
Labels
kind/bug
Something isn't working.
kind/enhancement
New feature or request.
kind/maintenance
Refactoring task or improving code health status.
We would like to use a polymorphic ADT as the message protocol between two Streamlets. Let's say for example I would like to design a
SubscriptionProtocol
with the following commands:SubscribeCmd
UnsubscribeCmd
And I would like to use this as the protocol between two Streamlets with Avro. We can tune
avrohugger
in ourbuild.sbt
to generate ADTs from Avro IDL files. See below with the following example protocol:And the following sbt configuration for our
datamodel
module:This will generate the following code for us (note: simplified)
However when we use this as the protocol in our Inlets and Outlets with our Streamlets it doesn't work:
So I was stuck on this approach.
Alternative approach
Next I took another approach where I would wrap different command inside a generic event. Which looks something like this:
This also fails to compile due to a limitiaton in the
avrohugger
plugin, as it can't generate aunion
with different records, only nullable fielts. Also support julianpeeters/avrohugger#116 and below:We can fix this by using a
GenericRecordBase
, however theAvroInlets
andAvroOutlet
require a protocol which extendsSpecificRecordBase
. So we are stuck here too.Workaround
We now use a temporary workaround by defining option fields for each command:
This generates the following Scala code:
This works, but isn't pretty and not really extensible when we want to add more commands to this event.
Question
How could we support polymorphic ADTs in Cloudflow? Thanks!
Also see the discussion on [Gitter])https://gitter.im/lightbend/cloudflow?at=5e7ba8efaf5fed7748602ca8)
The text was updated successfully, but these errors were encountered: