Skip to content

Instantly share code, notes, and snippets.

@schroedermatt
Last active July 24, 2018 19:59
Show Gist options
  • Select an option

  • Save schroedermatt/3029cb714665b4813f1715a0f464fc62 to your computer and use it in GitHub Desktop.

Select an option

Save schroedermatt/3029cb714665b4813f1715a0f464fc62 to your computer and use it in GitHub Desktop.
Spring Kafka Config blog
@Configuration
public class TopicAdministrator {
private final TopicConfigurations configurations;
private final GenericWebApplicationContext context;
public TopicAdministrator(TopicConfigurations configurations, GenericWebApplicationContext genericContext) {
this.configurations = configurations;
this.context = genericContext;
}
@PostConstruct
public void createTopics() {
configurations
.getTopics()
.ifPresent(this::initializeBeans);
}
private void initializeBeans(List<TopicConfiguration> topics) {
topics.forEach(t -> {
context.registerBean(t.getName(), NewTopic.class, t::toNewTopic);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment