Skip to content

Commit

Permalink
演示如何通过shared kernel在core/sub domains里进行交互
Browse files Browse the repository at this point in the history
  • Loading branch information
funkygao committed Nov 16, 2020
1 parent 3f581d6 commit 4f50da7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.example.cp.oms.spec.exception.OrderException;
import org.example.cp.oms.domain.model.vo.ProductDelegate;
import org.example.cp.oms.spec.model.IOrderMain;
import org.example.cp.oms.spec.model.vo.IOrderItemDelegate;
import org.example.cp.oms.spec.model.vo.IProductDelegate;

import javax.validation.constraints.NotNull;
Expand Down Expand Up @@ -101,7 +102,12 @@ public void setX2(String x2) {

@Override
public IProductDelegate productDelegate() {
return null;
return productDelegate;
}

@Override
public IOrderItemDelegate itemDelegate() {
return orderItemDelegate;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class StockStep extends SubmitOrderStep {

@Override
public void execute(@NotNull OrderMain model) throws OrderException {
stockService.occupyStock("SKU098");
stockService.occupyStock(model);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.example.cp.oms.spec.model;

import io.github.dddplus.api.RequestProfile;
import org.example.cp.oms.spec.model.vo.IOrderItemDelegate;
import org.example.cp.oms.spec.model.vo.IProductDelegate;
import io.github.dddplus.model.IDomainModel;
import lombok.NonNull;
Expand All @@ -17,6 +18,8 @@ public interface IOrderMain extends IDomainModel {
*/
IProductDelegate productDelegate();

IOrderItemDelegate itemDelegate();

/**
* 获取当前的请求参数.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package org.example.cp.oms.spec.model.vo;

public interface IOrderItem {

String getSku();
Integer getQuantity();

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import io.github.dddplus.annotation.DomainService;
import lombok.extern.slf4j.Slf4j;
import org.example.cp.oms.spec.model.IOrderMain;
import org.example.cp.oms.spec.model.vo.IOrderItem;
import org.example.oms.d.stock.domain.facade.rpc.IRemoteStockRpc;
import org.example.oms.d.stock.spec.StockDomain;
import org.example.oms.d.stock.spec.service.IStockService;
Expand All @@ -16,10 +18,13 @@ public class StockService implements IStockService {
private IRemoteStockRpc remoteStockRpc;

@Override
public void occupyStock(String sku) {
public void occupyStock(IOrderMain orderMain) {
log.info("会通过infrastructure层调用库存中心的RPC接口,执行预占库存动作");
log.info("这里的逻辑,主要是根据不同业务场景组织库存中心RPC的入参,并对返回结果进行处理");

remoteStockRpc.doOccupy(sku, 5);
for (IOrderItem item : orderMain.itemDelegate().getItems()) {
// 生产环境,看到会批量调用,这里只是演示
remoteStockRpc.doOccupy(item.getSku(), item.getQuantity());
}
}
}
8 changes: 8 additions & 0 deletions order-center-domain-stock/order-center-stock-spec/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@

<!-- 支撑域的spec包,是不依赖core domain的spec包的:自治 -->

<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>cp-oc-spec</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package org.example.oms.d.stock.spec.service;

import io.github.dddplus.model.IDomainService;
import org.example.cp.oms.spec.model.IOrderMain;

// 库存相关的服务,都收敛在库存支撑域,通过领域服务提供给订单核心域调用:JVM内调用, not RPC
public interface IStockService extends IDomainService {

/**
* 预占预存.
*
* @param sku 商品的sku编号
* @param orderMain core domain提供的领域模型聚合根
*/
void occupyStock(String sku);
void occupyStock(IOrderMain orderMain);

}

0 comments on commit 4f50da7

Please sign in to comment.