Java 在spring boot和kafka同时更新到表时进行比赛

Java 在spring boot和kafka同时更新到表时进行比赛,java,spring-boot,spring-mvc,apache-kafka,spring-data,Java,Spring Boot,Spring Mvc,Apache Kafka,Spring Data,我在代码中有种族条件 在我的代码中运行kafka时 我的代码是微服务 我想在3个步骤中实现代码 1-创建订单 2-通过卡夫卡发送制作人,在我的分公司添加新订单,以便接受 3-卡夫卡将制作人发送至更改订单状态 但在我的代码中并没有实现所有步骤,在调试代码时,我会毫无例外地进入所有方法 但我在运行代码时有两种情况 1-在分支上添加订单而不更改状态订单(在数据库中) 2-更改订单状态,而不在分支上添加新订单 看看我的方法: 在分支上添加订单并更改状态 这是控制器 @PostMapping("

我在代码中有种族条件 在我的代码中运行kafka时 我的代码是微服务

我想在3个步骤中实现代码 1-创建订单 2-通过卡夫卡发送制作人,在我的分公司添加新订单,以便接受 3-卡夫卡将制作人发送至更改订单状态 但在我的代码中并没有实现所有步骤,在调试代码时,我会毫无例外地进入所有方法
但我在运行代码时有两种情况 1-在分支上添加订单而不更改状态订单(在数据库中) 2-更改订单状态,而不在分支上添加新订单

看看我的方法: 在分支上添加订单并更改状态

这是控制器

@PostMapping("v1/branch/{branchId}/orders")
public ResponseEntity<AscOrderDTO> createOrder(@PathVariable Long branchId,@RequestBody AscOrderDTO ascOrderDTO)
{
    try {
        AscOrderDTO result=ascOrderService.createOrder(branchId,ascOrderDTO);// success code without any wrong 
        producerOrder.addOrder(branchId, result.getId()); // here call producer for save order on branch
        return ResponseEntity.ok().body(result);
    } catch (Exception e) {
        // TODO: handle exception
        throw new BadRequestAlertException(e.getMessage(), e.getMessage(), e.getMessage());
    }
}
最后是变更状态代码

    // change Order Status
public void changeStatus(OrderEvent event, Long orderId) throws Exception {
    try {
        if (!ascOrderRepository.findById(orderId).isPresent()) {

            throw new BadRequestAlertException("cannot find Order", "Order entity", "Id invalid");
        }
        log.debug("i am in changeStatus ");
        stateMachineHandler.stateMachine(event, orderId);
        stateMachineHandler.handling(orderId);

    } catch (Exception e) {
        throw new Exception(e.getMessage());
    }
}
    // change Order Status
public void changeStatus(OrderEvent event, Long orderId) throws Exception {
    try {
        if (!ascOrderRepository.findById(orderId).isPresent()) {

            throw new BadRequestAlertException("cannot find Order", "Order entity", "Id invalid");
        }
        log.debug("i am in changeStatus ");
        stateMachineHandler.stateMachine(event, orderId);
        stateMachineHandler.handling(orderId);

    } catch (Exception e) {
        throw new Exception(e.getMessage());
    }
}