mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2026-04-23 19:08:35 +08:00
update 优化 完善kafka案例
This commit is contained in:
@@ -14,11 +14,11 @@ import org.springframework.stereotype.Component;
|
||||
public class KafkaNormalConsumer {
|
||||
|
||||
//默认获取最后一条消息
|
||||
@KafkaListener(topics = "test-topic",groupId = "demo")
|
||||
public void timiKafka(ConsumerRecord record){
|
||||
@KafkaListener(topics = "test-topic", groupId = "test-group-id")
|
||||
public void timiKafka(ConsumerRecord<String, String> record) {
|
||||
Object key = record.key();
|
||||
Object value = record.value();
|
||||
log.info("【消费者】received the message key {},value:{}",key,value);
|
||||
log.info("【消费者】received the message key {},value:{}", key, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* @author xbhog
|
||||
* @date 2024/05/19 18:02
|
||||
@@ -16,10 +14,9 @@ import java.util.concurrent.CompletableFuture;
|
||||
public class KafkaNormalProducer {
|
||||
|
||||
@Autowired
|
||||
private KafkaTemplate kafkaTemplate;
|
||||
private KafkaTemplate<String, String> kafkaTemplate;
|
||||
|
||||
public void sendKafkaMsg() {
|
||||
CompletableFuture send = kafkaTemplate.send("test-topic", "hello", "kafkaTest");
|
||||
send.join();
|
||||
kafkaTemplate.send("test-topic", "hello", "kafkaTest");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user