<dependency><groupId>org.springframework.kafka</groupId><artifactId>spring-kafka</artifactId></dependency>
spring:kafka:bootstrap-servers:- ip:端口producer:retries: 0acks: 1batch-size: 16384properties:linger:ms: 100buffer-memory: 33554432key-serializer: org.apache.kafka.common.serialization.StringSerializervalue-serializer: org.apache.kafka.common.serialization.StringSerializer
@Resourceprivate KafkaTemplate<String,String> kafkaTemplate;public void sendKfaka(JSONObject body){ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send("topic1", body);future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {@Overridepublic void onSuccess(SendResult<String, String> result) {// 消息成功发送的处理逻辑log.info("Message sent successfully to the topic: " + result.getRecordMetadata().topic() +" with offset: " + result.getRecordMetadata().offset());}@Overridepublic void onFailure(Throwable ex) {// 消息发送失败的处理逻辑log.error("Unable to send message to the topic: ",ex);}});}}