1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| @Data @Configuration @AutoConfigureAfter(ApmListenerConfig.class) public class ApmListenerFactory {
@Autowired private ApmListenerConfig config;
@Bean public ApplicationRunner runner(KafkaListenerEndpointRegistry registry, GenericApplicationContext context) { return args -> { Properties props = new Properties(); PropertiesPropertySource source = new PropertiesPropertySource("dynamicListener", props); context.getEnvironment().getPropertySources().addLast(source); config.getDetails().forEach(listener -> { ApmListener apmListener = new ApmListener(); props.setProperty("apm.topic", listener.getTopic()); props.setProperty("apm.groupId", listener.getGroupId()); props.setProperty("apm.concurrency", listener.getConcurrency()); context.registerBean(listener.getBeanName(), ApmListener.class, () -> apmListener); context.getBean(listener.getBeanName()); }); registry.getListenerContainerIds().forEach(System.out::println); }; } }
|