Hello @jmartin 
Going off what you have written, my first instinct would be to subscribe to BeanMetadata DataChangeEvents from the service whose BeanMetadata you need to know about. You can check if they meet the criteria by leveraging the filters on a DataChangeEventQuery. Then, you can upsert a new edition of BeanMetadata every time you receive a DataChangeEvent.
Couple things you need to know:
- The default Kafka topic name format for a generated Data Service is
<servicename>.datachangeevents.<type>
So if your service was called entity-service, you the topic you would subscribe to is:
entityservice.datachangeevents.beanmetadata
- To do this, I would generate a Functional Service, and configure it to subscribe to that aforementioned Kafka topic:
$ yo @leaf/functional-service
... (series of prompts)
? Enter the REST URI used for REST clients: http://entity-service/rest
Then, in the values/values.yaml, add the following under kafka:
kafka:
...
beanMetadataTopic: entityservice.datachangeevents.beanmetadata
Out of the box, Functional Services wire up a DataChangeEventManager and have a method that gets executed on each DataChangeEvent. In this method, you can leverage a MetadataServiceRestClient to add the fields to the existing BeanMetadata.
IMetadataService metadataServiceRestClient = MetadataServiceRestClient.newBuilder(webTarget).build()
You should be able to use the same webTarget that the generated DataObjectServiceRestClient uses.
void onDataChangeEvent(final DataChangeEvent<DataObject> dataChangeEvent) {
....
metadataServiceRestClient.upsertBeanMetadata(modifiedBeans, Context.makeSystemContext());
...
}
- In the
setupEventHandler() method, a DataChangeEventQuery should already be generated for you:
DataChangeEventQuery eventQuery = .... ;
Here you can tailor the Query to include whatever criteria you wish by adding filters.