Q1:Failed to start bean ‘org.springframework.kafka.config.internalKafkaListenerEndpointRegistry‘
A1:是因为没有在注入时未对其进行配置导致,注册参照如下
/** * Created by wolf 2018/12/1 */ @Configuration @EnableKafka public class kafkatemplateConfig { @Value("${spring.kafka.bootstrap-servers}") private String bootstrapServers; @Bean public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String,String>> kafkaListenerContainerFactory(){ ConcurrentKafkaListenerContainerFactory<String,String> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory()); factory.setConcurrency(3); factory.getContainerProperties().setPollTimeout(5000); return factory; } @Bean public ConsumerFactory<String,String> consumerFactory(){ return new DefaultKafkaConsumerFactory<>(consumerConfigs()); } @Bean public Map<String,Object> consumerConfigs(){ Map<String,Object> propsMap = new HashMap<>(); propsMap.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,this.bootstrapServers); propsMap.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG,false);//自行控制提交offset propsMap.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG,"100");//提交延迟毫秒数 propsMap.put(ConsumerConfig.SESSION_TIMEOUT_MS_CONFIG,"15000");//执行超时时间 propsMap.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); propsMap.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); propsMap.put(ConsumerConfig.GROUP_ID_CONFIG,"dsafas"); propsMap.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,"latest");//开始消费位置 return propsMap; } @Bean public Consumer listener(){ return new Consumer(); } }
Q2:a:Could not instantiate class org.springframework.kafka.support.serializer.JsonDeserializer
b:org.springframework.kafka.support.serializer.JsonDeserializer with modifiers "protected"
c:If the serializationyou can also enable trust all (*)
A2:看下是因为要为监听者得到的对象 在进行序列化与反序列化 要进行设置在上述配置类中如下两列针对该问题
propsMap.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); propsMap.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
Q3:java.lang.IllegalArgumentException: Magic v1 does not support record headers
A3:版本问题 我其实遇到时是用的 springboot.version: 2.1.0.RELEASE 部署的kafka组件版本为较新版kafka_2.11-2.1.0 与旧版kafka_2.12-0.10.2.1 最终将springboot.version换成1.5.10.RELEASE
原文地址:https://www.cnblogs.com/nhz-M/p/10048047.html
时间: 2024-10-08 14:58:50