org.axonframework.eventsourcing.IncompatibleAggregateException(Axon框架:应用事件后聚合标识符必须为非null)

问题描述 投票:2回答:1

我尝试使用axon配置cqrs和事件源。 SeatReseveCreateCommand工作正常。但SeatReserveUpadateCommand无法正常工作。

这是我的SeatReserve聚合

@Aggregate
public class SeatReserve {
    @AggregateIdentifier
    private String id;
    private String seatid;
    private Date date;

    @SuppressWarnings("unused")
    private SeatReserve() {
    }

    @CommandHandler
    public SeatReserve(SeatReseveCreateCommand seatReseveCreateCommand) {
        apply(new SeatReseveCreateEvent(seatReseveCreateCommand.getMyid(), seatReseveCreateCommand.getSeatId(),
                seatReseveCreateCommand.getDate()));
    }

    @CommandHandler
    public SeatReserve(SeatReserveUpadateCommand upadateCommand) {
        apply(new SeatReserveUpadateEvent(id, upadateCommand.getSeatId()));
    }

    @EventSourcingHandler
    public void on(SeatReseveCreateEvent seatReseveCreateEvent) {
        this.id = seatReseveCreateEvent.getId();
        this.seatid = seatReseveCreateEvent.getSeatId();
        this.date = seatReseveCreateEvent.getDate();
    }

    @EventSourcingHandler
    public void on(SeatReserveChangeEvent upadateEvent) {
        seatid = upadateEvent.getSeatId();
    }

}

这是我的控制器

@RestController
public class TestController {

    private final CommandGateway commandGateway;

    public TestController(CommandGateway commandGateway) {
        this.commandGateway=commandGateway;
    }

    @PostMapping
    public String fileComplaint(@RequestBody Map<String, String> request) {
        String id = UUID.randomUUID().toString();
        SeatReseveCreateCommand command=new SeatReseveCreateCommand(id,request.get("seatid"),new Date(request.get("date")));
        commandGateway.send(command);
        return id;   
    }
    @PatchMapping
    public String fileComplaintUpdate(@RequestBody Map<String, String> request) {
        SeatReserveUpadateCommand command= new SeatReserveUpadateCommand(request.get("id"),request.get("seatid"));
        commandGateway.send(command);
        return request.get("id");
    }
}

我尝试使用邮递员发送请求

这是我的创建请求

enter image description here

这是我的更新请求

enter image description here

更新发生此错误

2018-01-03 10:44:53.608  WARN 11138 --- [nio-8085-exec-1] o.a.c.gateway.DefaultCommandGateway      : Command 'com.thamira.research.api.bankaccount.SeatReserveUpadateCommand' resulted in org.axonframework.eventsourcing.IncompatibleAggregateException(Aggregate identifier must be non-null after applying an event. Make sure the aggregate identifier is initialized at the latest when handling the creation event.)

我该怎么解决这个问题。

spring-boot microservices cqrs event-sourcing axon
1个回答
5
投票

问题是您的更新命令被定义为构造函数。该命令应该转到现有的聚合实例。

将命令处理程序更改为:

@CommandHandler
public void handle(SeatReserveUpadateCommand upadateCommand) {...}

应该解决这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.