Use Spring's ApplicationContext to instantiate exporter arguments #7628
Labels
area/ux
Marks an issue as related to improving the user experience
kind/toil
Categorizes an issue or PR as general maintenance, i.e. cleanup, refactoring, etc.
scope/broker
Marks an issue or PR to appear in the broker section of the changelog
scope/gateway
Marks an issue or PR to appear in the gateway section of the changelog
version:8.1.0-alpha4
version:8.1.0
Marks an issue as being completely or in parts released in 8.1.0
Description
One of the biggest downside with exporters is that arguments are parsed as an intermediate map by Spring. We then use
Gson
to instantiate a bean from that map. That's primarily due to historical reasons, where our configuration used to beTOML
and parsed byGson
- at the time it made sense to simply reuse this. However, what happens now is that we have differences between how the normal Zeebe configuration is parsed and how exporter configuration is instantiated.The goal here is to align this, such that there is no difference, and the exporter configuration is parsed like any Spring Boot configuration. Since we cannot guarantee that these classes are annotated correctly - and we don't want to enforce it to avoid coupling user code to Spring Boot - we can use an adapter for the
ApplicationContext
which will let us dynamically register beans at run time, and then instantiate them correctly.As mentioned, this must be done in two phases. Spring can only instantiate beans from a set of definitions. At startup, it scans the class path (or whatever you defined) and loads the bean definitions via annotations. If your class is not annotated, or wasn't scanned, then it won't know it, and cannot instantiate anything from it. Once a bean definition (i.e. a class and a name) is registered, then it can be easily instantiated without any issue.
See this example:
Using this, you can then call
springBeanFactory.createBean("zeebe.broker", BrokerCfg.class)
which will instantiate the configuration by looking up the property "zeebe.broker". You don't even need to annotate theBrokerCfg
class, which would also let us remove the Spring dependency on the broker module.The text was updated successfully, but these errors were encountered: