1. 搭建新的 Nacos 服务,并替换配置文件
2. 引入 Spring Cloud Stream RocketMQ 依赖,并接入 product 模块
This commit is contained in:
parent
d0ae7e61b3
commit
3dd7f2d0af
@ -11,7 +11,7 @@ spring:
|
|||||||
nacos:
|
nacos:
|
||||||
# Spring Cloud Nacos Discovery 配置项
|
# Spring Cloud Nacos Discovery 配置项
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
|
||||||
|
|
||||||
# mybatis-plus
|
# mybatis-plus
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
@ -27,7 +27,7 @@ mybatis-plus:
|
|||||||
dubbo:
|
dubbo:
|
||||||
# Dubbo 注册中心
|
# Dubbo 注册中心
|
||||||
registry:
|
registry:
|
||||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
||||||
# Spring Cloud Alibaba Dubbo 专属配置
|
# Spring Cloud Alibaba Dubbo 专属配置
|
||||||
cloud:
|
cloud:
|
||||||
subscribed-services: admin-application, user-application, product-application, promotion-application, pay-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
subscribed-services: admin-application, user-application, product-application, promotion-application, pay-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||||
|
@ -11,7 +11,7 @@ spring:
|
|||||||
nacos:
|
nacos:
|
||||||
# Spring Cloud Nacos Discovery 配置项
|
# Spring Cloud Nacos Discovery 配置项
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
|
||||||
|
|
||||||
# mybatis
|
# mybatis
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
@ -23,7 +23,7 @@ mybatis-plus:
|
|||||||
dubbo:
|
dubbo:
|
||||||
# Dubbo 注册中心
|
# Dubbo 注册中心
|
||||||
registry:
|
registry:
|
||||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
||||||
# Spring Cloud Alibaba Dubbo 专属配置
|
# Spring Cloud Alibaba Dubbo 专属配置
|
||||||
cloud:
|
cloud:
|
||||||
subscribed-services: admin-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
subscribed-services: admin-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||||
|
15
pom.xml
15
pom.xml
@ -57,9 +57,6 @@
|
|||||||
|
|
||||||
<servlet.version>2.5</servlet.version>
|
<servlet.version>2.5</servlet.version>
|
||||||
|
|
||||||
<prometheus-spring-boot.version>0.6.0</prometheus-spring-boot.version>
|
|
||||||
<micrometer.version>1.4.1</micrometer.version>
|
|
||||||
|
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<hibernate-validator.version>6.0.16.Final</hibernate-validator.version>
|
<hibernate-validator.version>6.0.16.Final</hibernate-validator.version>
|
||||||
<fastjson.version>1.2.56</fastjson.version>
|
<fastjson.version>1.2.56</fastjson.version>
|
||||||
@ -201,18 +198,6 @@
|
|||||||
<version>${spring-boot-admin-starter-client.version}</version>
|
<version>${spring-boot-admin-starter-client.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.micrometer</groupId>
|
|
||||||
<artifactId>micrometer-registry-prometheus</artifactId>
|
|
||||||
<version>${micrometer.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.prometheus</groupId>
|
|
||||||
<artifactId>simpleclient_spring_boot</artifactId>
|
|
||||||
<version>${prometheus-spring-boot.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Test 相关 -->
|
<!-- Test 相关 -->
|
||||||
|
|
||||||
<!--- 日志相关 -->
|
<!--- 日志相关 -->
|
||||||
|
@ -64,8 +64,8 @@
|
|||||||
|
|
||||||
<!-- MQ 相关 -->
|
<!-- MQ 相关 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.rocketmq</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
<artifactId>rocketmq-spring-boot-starter</artifactId>
|
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- 工具类相关 -->
|
<!-- 工具类相关 -->
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package cn.iocoder.mall.product.config;
|
||||||
|
|
||||||
|
import cn.iocoder.mall.product.message.MQStreamProducer;
|
||||||
|
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableBinding(MQStreamProducer.class)
|
||||||
|
public class MQStreamConfiguration {
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package cn.iocoder.mall.product.message;
|
||||||
|
|
||||||
|
import org.springframework.cloud.stream.annotation.Output;
|
||||||
|
import org.springframework.messaging.MessageChannel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spring Cloud Stream Source 接口
|
||||||
|
*/
|
||||||
|
public interface MQStreamProducer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品更新 Output
|
||||||
|
*/
|
||||||
|
String PRODUCT_UPDATE_OUTPUT = "product-update-output";
|
||||||
|
|
||||||
|
@Output(PRODUCT_UPDATE_OUTPUT)
|
||||||
|
MessageChannel productUpdateOutput();
|
||||||
|
|
||||||
|
// default boolean sendProductUpdateMessage(ProductUpdateMessage message) {
|
||||||
|
// // 创建 Spring Message 对象
|
||||||
|
// Message<ProductUpdateMessage> springMessage = MessageBuilder.withPayload(message)
|
||||||
|
// .build();
|
||||||
|
// // 发送消息
|
||||||
|
// return productUpdateOutput().send(springMessage);
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
@ -31,7 +31,6 @@ public class ProductSpuCollectionServiceImpl implements ProductSpuCollectionServ
|
|||||||
@Resource
|
@Resource
|
||||||
private RocketMQTemplate rocketMQTemplate;
|
private RocketMQTemplate rocketMQTemplate;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean productSpuCollection(Integer spuId, Integer hasCollectionType, Integer userId) {
|
public boolean productSpuCollection(Integer spuId, Integer hasCollectionType, Integer userId) {
|
||||||
ProductSpuDO productSpuDO = this.productSpuMapper.selectById(spuId);
|
ProductSpuDO productSpuDO = this.productSpuMapper.selectById(spuId);
|
||||||
@ -48,6 +47,7 @@ public class ProductSpuCollectionServiceImpl implements ProductSpuCollectionServ
|
|||||||
* @param productSpuDO
|
* @param productSpuDO
|
||||||
* @param hasCollectionType
|
* @param hasCollectionType
|
||||||
*/
|
*/
|
||||||
|
// TODO FROM 芋艿 to ??:切换到 Spring Cloud Stream 发送消息
|
||||||
private void sendProductSpuCollectionMessage(final ProductSpuDO productSpuDO, final Integer hasCollectionType,
|
private void sendProductSpuCollectionMessage(final ProductSpuDO productSpuDO, final Integer hasCollectionType,
|
||||||
final Integer userId) {
|
final Integer userId) {
|
||||||
List<String> result = Lists.newArrayList(Splitter.on(",").omitEmptyStrings().trimResults().split(productSpuDO.getPicUrls()));
|
List<String> result = Lists.newArrayList(Splitter.on(",").omitEmptyStrings().trimResults().split(productSpuDO.getPicUrls()));
|
||||||
|
@ -17,13 +17,14 @@ import cn.iocoder.mall.product.dao.ProductSpuMapper;
|
|||||||
import cn.iocoder.mall.product.dataobject.ProductCategoryDO;
|
import cn.iocoder.mall.product.dataobject.ProductCategoryDO;
|
||||||
import cn.iocoder.mall.product.dataobject.ProductSkuDO;
|
import cn.iocoder.mall.product.dataobject.ProductSkuDO;
|
||||||
import cn.iocoder.mall.product.dataobject.ProductSpuDO;
|
import cn.iocoder.mall.product.dataobject.ProductSpuDO;
|
||||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
import cn.iocoder.mall.product.message.MQStreamProducer;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.messaging.Message;
|
||||||
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -41,8 +42,8 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ProductAttrServiceImpl productAttrService;
|
private ProductAttrServiceImpl productAttrService;
|
||||||
|
|
||||||
@Resource
|
@Autowired
|
||||||
private RocketMQTemplate rocketMQTemplate;
|
private MQStreamProducer mqStreamProducer;
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// public ProductSpuBO getProductSpuDetail(Integer id) {
|
// public ProductSpuBO getProductSpuDetail(Integer id) {
|
||||||
@ -346,8 +347,14 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
|||||||
spu.setQuantity(skus.stream().mapToInt(ProductSkuAddOrUpdateDTO::getQuantity).sum()); // 求库存之和
|
spu.setQuantity(skus.stream().mapToInt(ProductSkuAddOrUpdateDTO::getQuantity).sum()); // 求库存之和
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendProductUpdateMessage(Integer id) {
|
private boolean sendProductUpdateMessage(Integer id) {
|
||||||
rocketMQTemplate.convertAndSend(ProductUpdateMessage.TOPIC, new ProductUpdateMessage().setId(id));
|
// 创建 Message 对象
|
||||||
|
ProductUpdateMessage message = new ProductUpdateMessage().setId(id);
|
||||||
|
// 创建 Spring Message 对象
|
||||||
|
Message<ProductUpdateMessage> springMessage = MessageBuilder.withPayload(message)
|
||||||
|
.build();
|
||||||
|
// 发送消息
|
||||||
|
return mqStreamProducer.productUpdateOutput().send(springMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,25 @@ spring:
|
|||||||
nacos:
|
nacos:
|
||||||
# Spring Cloud Nacos Discovery 配置项
|
# Spring Cloud Nacos Discovery 配置项
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
|
||||||
|
|
||||||
|
# Spring Cloud Stream 配置
|
||||||
|
stream:
|
||||||
|
# Binding 配置项
|
||||||
|
bindings:
|
||||||
|
product-update-output:
|
||||||
|
destination: ProductUpdate
|
||||||
|
# Spring Cloud Stream RocketMQ 配置项
|
||||||
|
rocketmq:
|
||||||
|
# RocketMQ Binder 配置项
|
||||||
|
binder:
|
||||||
|
name-server: s1.iocoder.cn:9876 # RocketMQ Namesrv 地址
|
||||||
|
# RocketMQ 默认 Binding 配置项
|
||||||
|
default:
|
||||||
|
# RocketMQ 生产者
|
||||||
|
producer:
|
||||||
|
group: product-producer-group # 生产者分组
|
||||||
|
sync: true # 是否同步发送消息,默认为 false 异步。
|
||||||
|
|
||||||
# mybatis
|
# mybatis
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
@ -23,7 +41,7 @@ mybatis-plus:
|
|||||||
dubbo:
|
dubbo:
|
||||||
# Dubbo 注册中心
|
# Dubbo 注册中心
|
||||||
registry:
|
registry:
|
||||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
||||||
# Spring Cloud Alibaba Dubbo 专属配置
|
# Spring Cloud Alibaba Dubbo 专属配置
|
||||||
cloud:
|
cloud:
|
||||||
subscribed-services: admin-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
subscribed-services: admin-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||||
@ -50,12 +68,6 @@ dubbo:
|
|||||||
ProductSpuCollectionService:
|
ProductSpuCollectionService:
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
|
|
||||||
# rocketmq
|
|
||||||
rocketmq:
|
|
||||||
name-server: 127.0.0.1:9876
|
|
||||||
producer:
|
|
||||||
group: product-producer-group
|
|
||||||
|
|
||||||
# Seata 配置项
|
# Seata 配置项
|
||||||
seata:
|
seata:
|
||||||
# Seata 注册中心配置项
|
# Seata 注册中心配置项
|
||||||
|
@ -12,7 +12,7 @@ spring:
|
|||||||
nacos:
|
nacos:
|
||||||
# Spring Cloud Nacos Discovery 配置项
|
# Spring Cloud Nacos Discovery 配置项
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
|
||||||
|
|
||||||
# mybatis-plus
|
# mybatis-plus
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
@ -28,7 +28,7 @@ mybatis-plus:
|
|||||||
dubbo:
|
dubbo:
|
||||||
# Dubbo 注册中心
|
# Dubbo 注册中心
|
||||||
registry:
|
registry:
|
||||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
||||||
# Spring Cloud Alibaba Dubbo 专属配置
|
# Spring Cloud Alibaba Dubbo 专属配置
|
||||||
cloud:
|
cloud:
|
||||||
subscribed-services: admin-application, product-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
subscribed-services: admin-application, product-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||||
|
@ -12,13 +12,13 @@ spring:
|
|||||||
nacos:
|
nacos:
|
||||||
# Spring Cloud Nacos Discovery 配置项
|
# Spring Cloud Nacos Discovery 配置项
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
|
||||||
|
|
||||||
# Dubbo 配置项
|
# Dubbo 配置项
|
||||||
dubbo:
|
dubbo:
|
||||||
# Dubbo 注册中心
|
# Dubbo 注册中心
|
||||||
registry:
|
registry:
|
||||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
||||||
# Spring Cloud Alibaba Dubbo 专属配置
|
# Spring Cloud Alibaba Dubbo 专属配置
|
||||||
cloud:
|
cloud:
|
||||||
subscribed-services: admin-application, order-application, product-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
subscribed-services: admin-application, order-application, product-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
spring:
|
spring:
|
||||||
# datasource
|
# datasource
|
||||||
datasource:
|
datasource:
|
||||||
url: jdbc:mysql://180.167.213.26:13306/mall_admin?useSSL=false&useUnicode=true&characterEncoding=UTF-8
|
url: jdbc:mysql://s1.iocoder.cn:3306/mall_admin?useSSL=false&useUnicode=true&characterEncoding=UTF-8
|
||||||
driver-class-name: com.mysql.jdbc.Driver
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
username: root
|
username: root
|
||||||
password: ${MALL_MYSQL_PASSWORD}
|
password: ${MALL_MYSQL_PASSWORD}
|
||||||
@ -11,7 +11,7 @@ spring:
|
|||||||
nacos:
|
nacos:
|
||||||
# Spring Cloud Nacos Discovery 配置项
|
# Spring Cloud Nacos Discovery 配置项
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
|
||||||
|
|
||||||
# mybatis-plus
|
# mybatis-plus
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
@ -37,7 +37,7 @@ sms:
|
|||||||
dubbo:
|
dubbo:
|
||||||
# Dubbo 注册中心
|
# Dubbo 注册中心
|
||||||
registry:
|
registry:
|
||||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
||||||
# Spring Cloud Alibaba Dubbo 专属配置
|
# Spring Cloud Alibaba Dubbo 专属配置
|
||||||
cloud:
|
cloud:
|
||||||
subscribed-services: '' # 设置订阅的应用列表,默认为 * 订阅所有应用
|
subscribed-services: '' # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||||
|
@ -11,7 +11,7 @@ spring:
|
|||||||
nacos:
|
nacos:
|
||||||
# Spring Cloud Nacos Discovery 配置项
|
# Spring Cloud Nacos Discovery 配置项
|
||||||
discovery:
|
discovery:
|
||||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
|
||||||
|
|
||||||
# mybatis-plus
|
# mybatis-plus
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
@ -29,7 +29,7 @@ mybatis-plus:
|
|||||||
dubbo:
|
dubbo:
|
||||||
# Dubbo 注册中心
|
# Dubbo 注册中心
|
||||||
registry:
|
registry:
|
||||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
||||||
# Spring Cloud Alibaba Dubbo 专属配置
|
# Spring Cloud Alibaba Dubbo 专属配置
|
||||||
cloud:
|
cloud:
|
||||||
subscribed-services: admin-application, product-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
subscribed-services: admin-application, product-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||||
|
Loading…
Reference in New Issue
Block a user