JAVA全系列 教程
3762个小节阅读:7094.6k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
在kibana中创建商品索引
xxxxxxxxxx
PUT /goods
{
"settings": {
"number_of_shards": 5,
"number_of_replicas": 1,
"analysis": {
"analyzer": {
"ik_pinyin": {
"tokenizer": "ik_smart",
"filter": "pinyin_filter"
},
"tag_pinyin": {
"tokenizer": "keyword",
"filter": "pinyin_filter"
}
},
"filter": {
"pinyin_filter": {
"type": "pinyin",
"keep_joined_full_pinyin": true,
"keep_original": true,
"remove_duplicated_term": true
}
}
}
},
"mappings": {
"properties": {
"id": {
"type": "long",
"index": true
},
"goodsName": {
"type": "text",
"index": true,
"analyzer": "ik_pinyin",
"search_analyzer": "ik_smart"
},
"caption": {
"type": "text",
"index": true,
"analyzer": "ik_pinyin",
"search_analyzer": "ik_smart"
},
"tags": {
"type": "completion",
"analyzer": "tag_pinyin",
"search_analyzer": "tag_pinyin"
},
"price": {
"type": "double",
"index": true
},
"headerPic": {
"type": "keyword",
"index": true
},
"brand": {
"type": "keyword",
"index": true
},
"productType": {
"type": "keyword",
"index": true
},
"specification":{
"properties": {
"specificationName":{
"type": "keyword",
"index": true
},
"specificationOption":{
"type": "keyword",
"index": true
}
}
}
}
}
}
将mysql数据同步到redis中,修改商品服务配置文件
xxxxxxxxxx
# 端口号
server:
port: 9001
# 日志格式
logging:
pattern:
console: '%d{HH:mm:ss.SSS} %clr(%-5level) --- [%-15thread] %cyan(%-50logger{50}):%msg%n'
# 配置Mybatis-plus
mybatis-plus:
global-config:
db-config:
# 表名前缀
table-prefix: bz_
# 主键生成策略为自增
id-type: auto
configuration:
# 关闭列名自动驼峰命名映射规则
map-underscore-to-camel-case: false
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 开启sql日志
spring:
# 数据源
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql:///baizhanshopping?serverTimezone=UTC
url: jdbc:mysql://192.168.0.176:3306/baizhanshopping?serverTimezone=UTC
username: root
password: root
# rabbitmq
rabbitmq:
# host: 192.168.0.159
host: 192.168.0.176
port: 5672
username: guest
password: guest
virtual-host: /
dubbo:
application:
name: shopping_goods_service # 项目名
registry:
# address: zookeeper://192.168.0.159 # 注册中心地址
address: zookeeper://192.168.0.176 # 注册中心地址
port: 2181 # 注册中心端口号
timeout: 10000 # 注册到zk上超市时间,ms
protocol:
name: dubbo # dubbo使用的协议
port: -1 # 自动分配端口
scan:
base-packages: com.itbaizhan.shopping_goods_service.service # 包扫描
运行商品服务测试方法,查询商品后发送到MQ中
xxxxxxxxxx
@SpringBootTest
class ShoppingGoodsServiceApplicationTests {
@Autowired
private GoodsService goodsService;
// @DubboReference
// private SearchService searchService;
@Autowired
private RabbitTemplate rabbitTemplate;
@Test
void contextLoads() {
List<GoodsDesc> all = goodsService.findAll();
for (GoodsDesc goodsDesc : all) {
// searchService.syncGoodsToES(goodsDesc);
rabbitTemplate.convertAndSend("goods_exchange", "sync_goods", goodsDesc);
}
}
}
修改搜索服务配置文件,启动搜索服务,获取队列中的商品,同步到ES中
xxxxxxxxxx
# 端口号
server:
port: 9008
# 日志格式
logging:
pattern:
console: '%d{HH:mm:ss.SSS} %clr(%-5level) --- [%-15thread] %cyan(%-50logger{50}):%msg%n'
spring:
# elasticsearch
elasticsearch:
uris: http://192.168.0.80:9200
# rabbitmq
rabbitmq:
host: 192.168.0.80
port: 5672
username: guest
password: guest
virtual-host: /
dubbo:
application:
name: shopping_search_service # 项目名
registry:
address: zookeeper://192.168.0.80 # 注册中心地址
port: 2181 # 注册中心端口号
timeout: 10000 # 注册到zk上超市时间,ms
protocol:
name: dubbo # dubbo使用的协议
port: -1 # 自动分配端口
scan:
base-packages: com.itbaizhan.shopping_search_service.service # 包扫描