core-java icon indicating copy to clipboard operation
core-java copied to clipboard

Make the declaration of enriched subscriptions more explicit

Open armiol opened this issue 6 years ago • 0 comments

Currently, those who subscribe to the enriched events are obligated to perform a number of actions to obtain the enriched value. In particular:

  1. Use the EventContext to fetch the raw enrichment value by the enrichment name, which is a plain string.
  2. Unpack it from Any.
  3. Cast the unpacked value to the desired type.

While the steps aren't that difficult, they still aren't obvious and explicit enough. Thus introducing another possibility for mistakes.

The idea of this issue is to introduce the syntax, simplifying these steps. E.g.

@Subscribe
void on(TaskRenamed event, ProjectDetails projectEnrichment, UserDetails userEnrichment) {
    //...
}

In this way the framework detects two of the enrichments that are required, unpacks and casts the values and invokes the subscriber method, passing the values.

The legacy syntax still has to remain available.

Things still to consider:

  1. Multiple enrichments of the same type — which one to unpack and feed.
  2. Optionality of the enrichment values — how to handle the events, which aren't enriched.
  3. Potential clashes with the @Subscribe annotation behavior with the planned subscription to Entity states — currently there is no way to tell the difference between events, value objects and entity states. For the latter we may need to obligate Spine users to declare the entity type explicitly in the Protobuf definition.

armiol avatar Mar 12 '18 10:03 armiol