Skip to content

Instantly share code, notes, and snippets.

@Odilio
Created September 4, 2020 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Odilio/b067008cf3e013e6476880e3ef655d9b to your computer and use it in GitHub Desktop.
Save Odilio/b067008cf3e013e6476880e3ef655d9b to your computer and use it in GitHub Desktop.
package com.boilerplate.kafka.config;
import java.util.HashMap;
import java.util.Map;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.core.KafkaAdmin;
@Configuration
public class KafkaTopicConfig {
@Value(value = "${kafka.bootstrapAddress}")
private String bootstrapAddress;
@Value(value = "segundo")
private String topicName;
@Value(value = "mensagem")
private String messageTopicName;
@Bean
public KafkaAdmin kafkaAdmin() {
Map<String, Object> configs = new HashMap<>();
configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
return new KafkaAdmin(configs);
}
@Bean
public NewTopic topic1() {
return new NewTopic(topicName, 1, (short) 1);
}
@Bean
public NewTopic topic2() {
return new NewTopic(messageTopicName, 1, (short) 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment