SpringBoot版本2.x.x 具体是几,忘记了,是支持application.yml或者是application.properties配置的。当然也可以使用Java配置类。
以下是使用Java配置类来配置的。
import org.apache.kafka.clients.CommonClientConfigs;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.common.config.SaslConfigs;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.annotation.EnableKafka;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
import java.util.HashMap;
import java.util.Map;
@Configuration
@EnableKafka
public class KafkaConsumerConfig {
//指定kafka 代理集群地址,多个地址用英文逗号隔开
private String bootstrapServers="x.x.x.x:xxxx,x.x.x.x:xxxx";
//指定默认消费者group id,消费者监听到的也是这个
private String groupId="xxx";
//消费者在读取一个没有offset的分区或者offset无效时的策略,默认earliest是从头读,latest不是从头读
private String autoOffsetReset="earliest";
//是否自动提交偏移量offset,默认为true,一般是false,如果为f

最低0.47元/天 解锁文章
1568

被折叠的 条评论
为什么被折叠?



