private Map < String , Object > getConfigParams ( Class < ? > clazz ) { Map < String , Object > params = new HashMap <> ( ) ; for ( Field field : clazz . getDeclaredFields ( ) ) { if ( Modifier . isStatic ( field . getModifiers ( ) ) && field . getName ( ) . endsWith ( "_CONFIG" ) ) { try { String key = field . get ( null ) . toString ( ) ; String value = SpringUtil . getProperty ( "org.carewebframework.messaging.kafka." + key ) ; if ( value != null ) { params . put ( key , value ) ; } } catch ( Exception e ) { } } } return params ; }
A bit of a hack to return configuration parameters from the Spring property store as a map which is required to initialize Kafka consumers and producers . Uses reflection on the specified class to enumerate static fields with a name ending in _CONFIG . By Kafka convention these fields contain the names of configuration parameters .