赞
踩
Kafka的运行依赖于Zookeeper,所以在运行Kafka之前我们需要安装并运行Zookeeper
1)ZOOKEEPER_HOME:D:\machine\kafka_2.11-1.1.0
2)Path: 在现有的值后面添加";%ZOOKEEPER_HOME%\bin;"
打开cmd然后执行zkserver
https://www.apache.org/dyn/closer.cgi?path=/kafka/1.1.0/kafka_2.11-1.1.0.tgz
.\bin\windows\kafka-server-start.bat .\config\server.properties
启动过程报错,参考此链接:https://blog.csdn.net/weixin_44100514/article/details/88413870 可解决
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic testDemo
5.1:可以查看创建的topics:进入D:\machine\kafka_2.11-1.1.0\bin\windows目录:
kafka-topics.bat --describe --zookeeper localhost:2181 --topic testDemo
(1)Producer
进入目录D:\machine\kafka_2.11-1.1.0\bin\windows输入如下命令:
kafka-console-producer.bat --broker-list localhost:9092 --topic testDemo
(2)Consumer
进入目录D:\machine\kafka_2.11-1.1.0\bin\windows输入如下命令:
kafka-console-consumer.bat --zookeeper localhost:2181 --topic testDemo
然后就可以在Producer中发信息,在Consumer中收信息了
新建maven项目:
选择工作空间目录:
选择项目:
编写项目组和名称 finish:
修改pom.xml文件:
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(“hello”)
public class OneController {
@RequestMapping("")
public String hello() {
return "helloworld";
}
}
app.java:
package com.test.kafkatest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
*/
@SpringBootApplication
public class App
{
public static void main( String[] args )
{
System.out.println( “Hello World!” );
SpringApplication.run(App.class, args);
}
}
启动访问http://localhost:8012/hello即可:
参考链接:
1、https://www.cnblogs.com/mh-study/p/9537970.html
2、https://blog.csdn.net/tiantangdizhibuxiang/article/details/80556064
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。