Matan Perelmuter
03/10/2024, 4:51 PMTamir Sagi
03/11/2024, 9:19 AMMatan Perelmuter
03/11/2024, 10:09 AMTamir Sagi
03/11/2024, 10:18 AMpublic class AsyncTenantConfigOperator extends RichAsyncFunction<Tuple2String,EventData, Tuple2EventData, TenantData> {
@Override
public void asyncInvoke(final Tuple2String, EventData input,
final ResultFuture<Tuple2EventData, TenantData> resultFuture) throws Exception {
.
.
.
}
}
in that operator you can use postgress client to fetch configuration based on the tenant id and forward a new stream record where each configuration is attached to its tenant. the output can be something like Tuple2EventData, TenantData where TenantData includes tenant id + configuration
or alternatively Tuple3 TenantId, EventData, TenantConfig.
1. You better cache the configurations (tenantId, TenantConfig)
2. you can create a config provider which handles the cache and the client(i.e TenantConfigProvider). then just expose a method getTenantConfig(tenantId)
3. Keep in mind the parallelism of that instance + each client maintains connection pool internally. (The cache helps here to avoid overwhelming the external system)
Alternatively, if you have a service that maintains these configurations (i.e TenantConfigService) you can communicate with that service instead via REST client and not directly with the DB.(Same idea)
https://nightlies.apache.org/flink/flink-docs-master/docs/dev/datastream/operators/asyncio/Matan Perelmuter
03/11/2024, 11:57 AMTenantConfigProvider which will provide built-in cache handling and such, but seems like I just need plain old javaTamir Sagi
03/11/2024, 12:04 PM