Spring Boot集成Docker Kafka消息消费失败及Eureka缓存刷新异常问题求助
Hey there, let's tackle your two issues one by one—first the Kafka consumer conversion problem, then the Eureka client error.
Root Cause
Your producer is sending a JSON string (you used ObjectMapper.writeValueAsString() to convert the Map to JSON), but your consumer is directly expecting a Map<String,String> as the payload. Spring Kafka doesn't automatically convert JSON strings to Map types out of the box—you need to explicitly configure a message converter or handle the conversion manually.
Solution 1: Configure a JSON Message Converter
Add a StringJsonMessageConverter to your Kafka listener container factory, which tells Spring to automatically parse incoming JSON strings into your target type (Map in this case):
@Configuration public class KafkaConfig { @Bean public ConcurrentKafkaListenerContainerFactory<String, Object> kafkaListenerContainerFactory( ConsumerFactory<String, Object> consumerFactory) { ConcurrentKafkaListenerContainerFactory<String, Object> factory = new ConcurrentKafkaListenerContainerFactory<>(); factory.setConsumerFactory(consumerFactory); // Enable JSON-to-object conversion factory.setMessageConverter(new StringJsonMessageConverter()); return factory; } }
Then update your @KafkaListener annotation to use this custom container factory:
@KafkaListener(topics = TOPIC, groupId = groupId, containerFactory = "kafkaListenerContainerFactory") public void processUpdateRating(@Payload Map<String,String> rate) { branchService.rateUpdate(Double.parseDouble(rate.get("rate")),Long.parseLong(rate.get("branchId"))); log.debug("done update in queue"); }
Solution 2: Manually Parse the JSON String
If you don't want to configure a converter, you can modify the consumer to first receive the raw string, then parse it to a Map using ObjectMapper:
@KafkaListener(topics = TOPIC ,groupId = groupId) public void processUpdateRating(@Payload String rateJson) throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); // Use TypeReference to specify the generic Map type Map<String,String> rate = mapper.readValue(rateJson, new TypeReference<Map<String,String>>() {}); branchService.rateUpdate(Double.parseDouble(rate.get("rate")),Long.parseLong(rate.get("branchId"))); log.debug("done update in queue"); }
Root Cause
This error usually stems from one of three issues:
- The Eureka server isn't running, or your client is using the wrong server URL/credentials
- A Jackson version mismatch between your client and Eureka server, causing JSON parsing failures
- GZIP compression issues (the server sends compressed responses that the client can't parse correctly)
Step-by-Step Fixes
Verify Eureka Server Access
- First, confirm the Eureka server is running at
http://localhost:8761/eureka/. Try accessing this URL in your browser—you should see the Eureka dashboard after enteringadmin/adminas credentials. - Double-check your client's Eureka configuration (in
application.ymlorapplication.properties):eureka: client: service-url: defaultZone: http://admin:admin@localhost:8761/eureka/ fetch-registry: true register-with-eureka: true instance: prefer-ip-address: true
- First, confirm the Eureka server is running at
Fix Jackson Version Conflicts
- If you're using Maven/Gradle, ensure you're not manually specifying Jackson dependency versions. Spring Boot manages compatible versions automatically—remove any explicit
jackson-databindor related dependencies from your build file.
- If you're using Maven/Gradle, ensure you're not manually specifying Jackson dependency versions. Spring Boot manages compatible versions automatically—remove any explicit
Disable GZIP Compression (Temporary Test)
- If the JSON parse error persists, try disabling GZIP on the Eureka server to rule out compression issues. Add this to the server's
application.yml:eureka: server: gzip: enabled: false
- If the JSON parse error persists, try disabling GZIP on the Eureka server to rule out compression issues. Add this to the server's
Check Network/Proxy Issues
- Ensure there's no firewall, proxy, or security group blocking your client from reaching
localhost:8761.
- Ensure there's no firewall, proxy, or security group blocking your client from reaching
内容的提问来源于stack exchange,提问作者Abdalrhman Alkraien

