1. 搭建新的 Nacos 服务,并替换配置文件
2. 引入 Spring Cloud Stream RocketMQ 依赖,并接入 product 模块
This commit is contained in:
parent
d0ae7e61b3
commit
3dd7f2d0af
@ -11,7 +11,7 @@ spring:
|
||||
nacos:
|
||||
# Spring Cloud Nacos Discovery 配置项
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
||||
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
|
||||
|
||||
# mybatis-plus
|
||||
mybatis-plus:
|
||||
@ -27,7 +27,7 @@ mybatis-plus:
|
||||
dubbo:
|
||||
# Dubbo 注册中心
|
||||
registry:
|
||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
# Spring Cloud Alibaba Dubbo 专属配置
|
||||
cloud:
|
||||
subscribed-services: admin-application, user-application, product-application, promotion-application, pay-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||
|
@ -11,7 +11,7 @@ spring:
|
||||
nacos:
|
||||
# Spring Cloud Nacos Discovery 配置项
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
||||
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
|
||||
|
||||
# mybatis
|
||||
mybatis-plus:
|
||||
@ -23,7 +23,7 @@ mybatis-plus:
|
||||
dubbo:
|
||||
# Dubbo 注册中心
|
||||
registry:
|
||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
# Spring Cloud Alibaba Dubbo 专属配置
|
||||
cloud:
|
||||
subscribed-services: admin-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||
|
15
pom.xml
15
pom.xml
@ -57,9 +57,6 @@
|
||||
|
||||
<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>
|
||||
<hibernate-validator.version>6.0.16.Final</hibernate-validator.version>
|
||||
<fastjson.version>1.2.56</fastjson.version>
|
||||
@ -201,18 +198,6 @@
|
||||
<version>${spring-boot-admin-starter-client.version}</version>
|
||||
</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 相关 -->
|
||||
|
||||
<!--- 日志相关 -->
|
||||
|
@ -64,8 +64,8 @@
|
||||
|
||||
<!-- MQ 相关 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.rocketmq</groupId>
|
||||
<artifactId>rocketmq-spring-boot-starter</artifactId>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
|
||||
</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
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean productSpuCollection(Integer spuId, Integer hasCollectionType, Integer userId) {
|
||||
ProductSpuDO productSpuDO = this.productSpuMapper.selectById(spuId);
|
||||
@ -48,6 +47,7 @@ public class ProductSpuCollectionServiceImpl implements ProductSpuCollectionServ
|
||||
* @param productSpuDO
|
||||
* @param hasCollectionType
|
||||
*/
|
||||
// TODO FROM 芋艿 to ??:切换到 Spring Cloud Stream 发送消息
|
||||
private void sendProductSpuCollectionMessage(final ProductSpuDO productSpuDO, final Integer hasCollectionType,
|
||||
final Integer userId) {
|
||||
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.ProductSkuDO;
|
||||
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.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -41,8 +42,8 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
||||
@Autowired
|
||||
private ProductAttrServiceImpl productAttrService;
|
||||
|
||||
@Resource
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
@Autowired
|
||||
private MQStreamProducer mqStreamProducer;
|
||||
|
||||
// @Override
|
||||
// public ProductSpuBO getProductSpuDetail(Integer id) {
|
||||
@ -346,8 +347,14 @@ public class ProductSpuServiceImpl implements ProductSpuService {
|
||||
spu.setQuantity(skus.stream().mapToInt(ProductSkuAddOrUpdateDTO::getQuantity).sum()); // 求库存之和
|
||||
}
|
||||
|
||||
private void sendProductUpdateMessage(Integer id) {
|
||||
rocketMQTemplate.convertAndSend(ProductUpdateMessage.TOPIC, new ProductUpdateMessage().setId(id));
|
||||
private boolean sendProductUpdateMessage(Integer 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:
|
||||
# Spring Cloud Nacos 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-plus:
|
||||
@ -23,7 +41,7 @@ mybatis-plus:
|
||||
dubbo:
|
||||
# Dubbo 注册中心
|
||||
registry:
|
||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
# Spring Cloud Alibaba Dubbo 专属配置
|
||||
cloud:
|
||||
subscribed-services: admin-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||
@ -50,12 +68,6 @@ dubbo:
|
||||
ProductSpuCollectionService:
|
||||
version: 1.0.0
|
||||
|
||||
# rocketmq
|
||||
rocketmq:
|
||||
name-server: 127.0.0.1:9876
|
||||
producer:
|
||||
group: product-producer-group
|
||||
|
||||
# Seata 配置项
|
||||
seata:
|
||||
# Seata 注册中心配置项
|
||||
|
@ -12,7 +12,7 @@ spring:
|
||||
nacos:
|
||||
# Spring Cloud Nacos Discovery 配置项
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
||||
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
|
||||
|
||||
# mybatis-plus
|
||||
mybatis-plus:
|
||||
@ -28,7 +28,7 @@ mybatis-plus:
|
||||
dubbo:
|
||||
# Dubbo 注册中心
|
||||
registry:
|
||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
# Spring Cloud Alibaba Dubbo 专属配置
|
||||
cloud:
|
||||
subscribed-services: admin-application, product-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||
|
@ -12,13 +12,13 @@ spring:
|
||||
nacos:
|
||||
# Spring Cloud Nacos Discovery 配置项
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
||||
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
|
||||
|
||||
# Dubbo 配置项
|
||||
dubbo:
|
||||
# Dubbo 注册中心
|
||||
registry:
|
||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
# Spring Cloud Alibaba Dubbo 专属配置
|
||||
cloud:
|
||||
subscribed-services: admin-application, order-application, product-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||
|
@ -1,7 +1,7 @@
|
||||
spring:
|
||||
# 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
|
||||
username: root
|
||||
password: ${MALL_MYSQL_PASSWORD}
|
||||
@ -11,7 +11,7 @@ spring:
|
||||
nacos:
|
||||
# Spring Cloud Nacos Discovery 配置项
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
||||
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
|
||||
|
||||
# mybatis-plus
|
||||
mybatis-plus:
|
||||
@ -37,7 +37,7 @@ sms:
|
||||
dubbo:
|
||||
# Dubbo 注册中心
|
||||
registry:
|
||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
# Spring Cloud Alibaba Dubbo 专属配置
|
||||
cloud:
|
||||
subscribed-services: '' # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||
|
@ -11,7 +11,7 @@ spring:
|
||||
nacos:
|
||||
# Spring Cloud Nacos Discovery 配置项
|
||||
discovery:
|
||||
server-addr: 127.0.0.1:8848 # Nacos 服务器地址
|
||||
server-addr: s1.iocoder.cn:8848 # Nacos 服务器地址
|
||||
|
||||
# mybatis-plus
|
||||
mybatis-plus:
|
||||
@ -29,7 +29,7 @@ mybatis-plus:
|
||||
dubbo:
|
||||
# Dubbo 注册中心
|
||||
registry:
|
||||
address: spring-cloud://127.0.0.1:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
address: spring-cloud://s1.iocoder.cn:8848 # 指定 Dubbo 服务注册中心的地址
|
||||
# Spring Cloud Alibaba Dubbo 专属配置
|
||||
cloud:
|
||||
subscribed-services: admin-application, product-application # 设置订阅的应用列表,默认为 * 订阅所有应用
|
||||
|
Loading…
Reference in New Issue
Block a user