第5章 Kafka
5.2Kafka入门
(1)下载Kafka
(2)修改配置文件
Windows下Kafka常用命令:
(1)启动zookeeper
(1)先跳到Kafka根目录 cd C:\work\kafka_2.12-2.2.0
(2)输入指令 bin\windows\zookeeper-server-start.bat config\zookeeper.properties
(2)启动Kafka
cd C:\work\kafka_2.12-2.2.0
bin\windows\kafka-server-start.bat config\server.properties
(3)创建名为 test 的 Topic(消息位置、分类)
bin/kafka-topics.bat --create --bootstrap-server localhost:9092 --partitions 5 --replication-factor 1 --topic test
–partitions:分区数
–replication-factor:副本数
(4)查看主题
kafka-topics.bat --list --bootstrap-server localhost:9092
其他命令用到再查
5.3 Spring整合Kafka
(1)引入依赖,版本号删除,用父pom中的就可以,防止冲突
(2)在application.properties添加Kafka配置
(3)编写Kafka测试类
5.4发送系统通知
(1)创建Event事件实体类型(将消息封装成事件)
(2)新建Event包,开发生产者和消费者
(3)添加Follow、Like、CommentController中的相关方法
(4)修改页面
kafka启动失败,将data目录下的kafka…删了
5.5显示系统通知
开发流程:
(1)在MessageMapper中添加相应方法
(2)在.Mapper文件中添加对应SQL方法
(3)在MessageService中添加方法
(4)接着MessageController中添加方法
(5)处理页面
6.1Elasticsearch入门
(1)修改elasticsearch配置文件
(2)下载中文分词插件
(3)安装Postman
bin目录下的elasticsearch.bat命令行常用命令:
(1)curl -X GET “localhost:9200/_cat/health?v” 查看集群健康状态
(2)curl -X GET “localhost:9200/_cat/nodes?v” 查看集群节点信息
(3)curl -X GET “localhost:9200/_cat/indices?v” 查看数据库有多少索引
(4)curl -X PUT “localhost:9200/test” 新建一个名为test的索引
(新建的索引还没有分片所以健康状态时yellow)
(5)curl -X DELETE “localhost:9200/test” 删除一个名为test的索引
Postman常用命令:
(1)与上面5个类似
(2)新建id=1的数据
(3)查询还是用get
(4)全搜
(5)多字段搜索
6.2 Spring整合Elasticsearch
(1)导包
(2)在application.perproties中配置
(3)在启动类解决netty冲突
(4)在dao中新建包实现增删改查elasticsearch的接口
6.3 开发社区搜索功能
(1)修改Mapper
(2)开发Service
功能没实现,明天看
出现的错误
1.ES 写索引报错 FORBIDDEN/12/index read-only / allow delete (api)解决方案
问题描述:在向elasticsearch中插入字段时出现blocked by: [FORBIDDEN/12/index read-only / allow delete (api)]的错误
解决办法:
curl -XPUT -H “Content-Type: application/json” http://127.0.0.1:9200/_all/_settings -d ‘{“index.blocks.read_only_allow_delete”: null}’
-all可以改为自己的索引名称,也可以直接执行