我正在嘗試運(yùn)行一個(gè)簡單的彈簧啟動(dòng)Kafka應(yīng)用程序,但我無法使其工作。我已經(jīng)遵循了各種教程,現(xiàn)在我正在實(shí)現(xiàn)這個(gè)教程,但是當(dāng)我啟動(dòng)應(yīng)用程序時(shí),就會(huì)發(fā)生這種情況:我可以在控制臺(tái)中寫入,但使用者不會(huì)收到任何消息。這是我的春季應(yīng)用課程:@SpringBootApplication(scanBasePackages = "com.springmiddleware")@ComponentScan("com.springmiddleware")@EnableAutoConfiguration@EntityScan("com.springmiddleware")public class SpringMiddlewareApplication implements CommandLineRunner{ public static void main(String[] args) throws Exception { SpringApplication.run(SpringMiddlewareApplication.class, args); } @Autowired private Producer sender; @Override public void run (String... strings) { sender.send("Hello world"); }}應(yīng)用:spring: kafka: bootstrap-servers: localhost:8080app: topic: foo: foo.tlogging: level: root: ERROR org.springframework.web: ERROR com.memorynotfound: DEBUG使用者類、生產(chǎn)者類及其配置的類與本教程中編寫的類相同。在我的服務(wù)器.properties文件中,我有:zookeeper.connect=localhost:8080和動(dòng)物園管理員屬性:clientPort=8080在應(yīng)用程序中指定的相同端口。在啟動(dòng)應(yīng)用程序之前,我運(yùn)行.\bin\windows\zookeeper-server-start.bat config\zookeeper.properties和.\bin\windows\kafka-server-start.bat config\server.properties
1 回答

茅侃侃
TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超22個(gè)贊
在應(yīng)用程序.yml 中,您指定了動(dòng)物園管理員端口,而不是 kafka 代理端口
spring: kafka: bootstrap-servers: localhost:8080
在上面,您應(yīng)該定義 kafka 代理的端口,即 server.properties 文件的值。port=
默認(rèn)情況下,Spring 啟動(dòng)應(yīng)用在端口 8080 上運(yùn)行,因此請不要對 Zookeeper 端口使用相同的端口,除非你已更改了彈簧啟動(dòng)應(yīng)用的默認(rèn)端口。
所以在服務(wù)器屬性中,有 和 ,在應(yīng)用程序.yml中,有如下:port=9092
zookeeper.connect=localhost:2181
spring: kafka: bootstrap-servers: localhost:9092
然后在動(dòng)物園管理員的屬性中,有.然后以相同的順序重新啟動(dòng)動(dòng)物園管理員,Kafka服務(wù)器和彈簧啟動(dòng)應(yīng)用程序。clientPort=2181
更新:
較新版本的 Kafka 使用,而不是在服務(wù)器屬性文件中使用。因此,請嘗試替換它。listeners=PLAINTEXT://localhost:9092
port=9092
添加回答
舉報(bào)
0/150
提交
取消