반응형

이전글: 2022.01.12 - [개발/spring] - [axon] command/query project 생성 - clone coding

 

[axon] command/query project 생성 - clone coding

2022.01.12 - [architecture/MSA] - [cqrs] axon framework [cqrs] axon framework 2022.01.11 - [architecture/MSA] - [arch] what is cqrs - 조회와 비조회의 엄연한 분리 [arch] what is cqrs - 조회와 비조회..

bangpurin.tistory.com

이전 글에 이어서 axon framework의 command에 대한 클론 코딩을 이어가던 중 실습 내용에 대한 고찰을 해본다.

참고)

  필수 어노테이션
command @TargetAggregateIdentifier
aggregate @Aggregate
@AggregateIdentifier

 

클론 코딩 참고 블로그는 아래와 같다: https://cla9.tistory.com/12?category=814447 

 

8. Command 어플리케이션 구현 - 3

1. 서론 지난 포스팅에서 Command Application에 대한 전반적인 구현을 마무리했습니다. 하지만 해당 프로그램은 근본적인 문제점을 안고 있습니다. 이번 포스팅에서는 발생되는 문제점과 이를 해결

cla9.tistory.com

따라해본다.

POST http://localhost:8080/holder
POST http://localhost:8080/account
POST http://localhost:8080/deposit
POST http://localhost:8080/withdrawal
POST http://localhost:8080/withdrawal
POST http://localhost:8080/withdrawal

위 글에도 써있지만 아래와 같은 순서로 잔고를 인출했을 때의 로그는 아래와 같다(withdrawal을 10원씩 4번째 호출했을 때이다).

다시 말하지만 api 한번 호출 시의 로그이다.

[nio-8080-exec-3] o.a.commandhandling.SimpleCommandBus     : Handling command [com.cqrs.command.commands.WithdrawMoneyCommand]
[nio-8080-exec-3] o.a.m.unitofwork.AbstractUnitOfWork      : Starting Unit Of Work
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.messaging.unitofwork.AbstractUnitOfWork$$Lambda$1197/0x00000008008b5040 for phase ROLLBACK
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase STARTED
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.messaging.unitofwork.UnitOfWork$$Lambda$1201/0x00000008008b4040 for phase COMMIT
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.messaging.unitofwork.UnitOfWork$$Lambda$1202/0x00000008008b4440 for phase ROLLBACK
[nio-8080-exec-3] o.a.a.c.event.axon.AxonServerEventStore  : Reading events for aggregate id 2b158c88-b810-4643-9db4-4096edea5621
[nio-8080-exec-3] c.c.command.aggregate.AccountAggregate   : >> applying AccountCreationEvent(holderID=76147ef5-280f-439e-b017-bcd04028f176, accountID=2b158c88-b810-4643-9db4-4096edea5621)
[nio-8080-exec-3] c.c.command.aggregate.AccountAggregate   : applying DepositMoneyEvent(holderID=76147ef5-280f-439e-b017-bcd04028f176, accountID=2b158c88-b810-4643-9db4-4096edea5621, amount=300)
[nio-8080-exec-3] c.c.command.aggregate.AccountAggregate   : balance 300
[nio-8080-exec-3] c.c.command.aggregate.AccountAggregate   : applying WithdrawMoneyEvent(holderID=76147ef5-280f-439e-b017-bcd04028f176, accountID=2b158c88-b810-4643-9db4-4096edea5621, amount=10)
[nio-8080-exec-3] c.c.command.aggregate.AccountAggregate   : balance 290
[nio-8080-exec-3] c.c.command.aggregate.AccountAggregate   : applying WithdrawMoneyEvent(holderID=76147ef5-280f-439e-b017-bcd04028f176, accountID=2b158c88-b810-4643-9db4-4096edea5621, amount=10)
[nio-8080-exec-3] c.c.command.aggregate.AccountAggregate   : balance 280
[nio-8080-exec-3] c.c.command.aggregate.AccountAggregate   : applying WithdrawMoneyEvent(holderID=76147ef5-280f-439e-b017-bcd04028f176, accountID=2b158c88-b810-4643-9db4-4096edea5621, amount=10)
[nio-8080-exec-3] c.c.command.aggregate.AccountAggregate   : balance 270
[nio-8080-exec-3] org.axonframework.messaging.Scope        : Clearing out ThreadLocal current Scope, as no Scopes are present
[ault-executor-3] o.a.a.c.e.AxonServerEventStoreClient     : Done request for 2b158c88-b810-4643-9db4-4096edea5621: 22ms, 5 events
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.modelling.command.LockingRepository$$Lambda$1300/0x0000000800a0d440 for phase CLEANUP
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.modelling.command.AbstractRepository$$Lambda$1301/0x0000000800a0d840 for phase ROLLBACK
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.modelling.command.AbstractRepository$$Lambda$1302/0x0000000800a0dc40 for phase PREPARE_COMMIT
[nio-8080-exec-3] c.c.command.aggregate.AccountAggregate   : handling WithdrawMoneyCommand(accountID=2b158c88-b810-4643-9db4-4096edea5621, holderID=76147ef5-280f-439e-b017-bcd04028f176, amount=10)
[nio-8080-exec-3] c.c.command.aggregate.AccountAggregate   : applying WithdrawMoneyEvent(holderID=76147ef5-280f-439e-b017-bcd04028f176, accountID=2b158c88-b810-4643-9db4-4096edea5621, amount=10)
[nio-8080-exec-3] c.c.command.aggregate.AccountAggregate   : balance 260
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1222/0x00000008008f3440 for phase AFTER_COMMIT
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1223/0x00000008008f3840 for phase ROLLBACK
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1225/0x00000008008f4040 for phase PREPARE_COMMIT
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1226/0x00000008008f4440 for phase COMMIT
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1227/0x00000008008f4840 for phase AFTER_COMMIT
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1228/0x00000008008f4c40 for phase CLEANUP
[nio-8080-exec-3] org.axonframework.messaging.Scope        : Clearing out ThreadLocal current Scope, as no Scopes are present
[nio-8080-exec-3] o.a.m.unitofwork.AbstractUnitOfWork      : Committing Unit Of Work
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase PREPARE_COMMIT
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.axonserver.connector.event.axon.AxonServerEventStore$AxonIQEventStorageEngine$$Lambda$1245/0x000000080091f040 for phase ROLLBACK
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.axonserver.connector.event.axon.AxonServerEventStore$AxonIQEventStorageEngine$$Lambda$1246/0x000000080091f440 for phase COMMIT
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase COMMIT
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase AFTER_COMMIT
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase CLEANUP
[nio-8080-exec-3] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase CLOSED

관련 dto..

WithdrawMoneyCommand.java
    @TargetAggregateIdentifier
    private String accountID;

/withdraw api의 aggregateId 인 acoountId 에 대한 모든 이벤트를 다시 불러오는 듯 하다. 즉 위 로그처럼 acoountId에 대한 모든 이벤트를 롤백하고(마치 계좌가 없던 것 처럼) 다시 첨부터 하는 것을 반복한다. 즉 여기서는 계좌 생성(/account), 입금(/deposit), 출금 n번(/withdraw)이다.

 

event sourced aggregate

신박하다.. 데이터의 정합성은 보장될 것 같은데 효율성은 떨어질 것 같다.

 

snapshot

그래서 클론 코딩에서 알려준대로 스냅샷을 적용하고 새로운 마음으로 계정생성1, 입금2, 인출3, 인출4, 인출5 를 해본다.

아래는 인출5 api실행 시 로그다.

[nio-8080-exec-5] o.a.commandhandling.SimpleCommandBus     : Handling command [com.cqrs.command.commands.WithdrawMoneyCommand]
[nio-8080-exec-5] o.a.m.unitofwork.AbstractUnitOfWork      : Starting Unit Of Work
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.messaging.unitofwork.AbstractUnitOfWork$$Lambda$1192/0x000000080087ac40 for phase ROLLBACK
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase STARTED
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.messaging.unitofwork.UnitOfWork$$Lambda$1196/0x0000000800879c40 for phase COMMIT
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.messaging.unitofwork.UnitOfWork$$Lambda$1197/0x0000000800879040 for phase ROLLBACK
[nio-8080-exec-5] o.a.a.c.event.axon.AxonServerEventStore  : Reading events for aggregate id f00088d7-c81a-432c-b010-28a88012f0eb
[ault-executor-4] o.a.a.c.e.AxonServerEventStoreClient     : Done request for f00088d7-c81a-432c-b010-28a88012f0eb: 12ms, 4 events
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : >> applying AccountCreationEvent(holderID=b232a9e8-d280-48bc-9d17-df03c9fe4071, accountID=f00088d7-c81a-432c-b010-28a88012f0eb)
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : applying DepositMoneyEvent(holderID=b232a9e8-d280-48bc-9d17-df03c9fe4071, accountID=f00088d7-c81a-432c-b010-28a88012f0eb, amount=400)
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : balance 400
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : applying WithdrawMoneyEvent(holderID=b232a9e8-d280-48bc-9d17-df03c9fe4071, accountID=f00088d7-c81a-432c-b010-28a88012f0eb, amount=10)
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : balance 390
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : applying WithdrawMoneyEvent(holderID=b232a9e8-d280-48bc-9d17-df03c9fe4071, accountID=f00088d7-c81a-432c-b010-28a88012f0eb, amount=10)
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : balance 380
[nio-8080-exec-5] org.axonframework.messaging.Scope        : Clearing out ThreadLocal current Scope, as no Scopes are present
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.modelling.command.LockingRepository$$Lambda$1246/0x00000008009c2c40 for phase CLEANUP
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.modelling.command.AbstractRepository$$Lambda$1247/0x00000008009c3040 for phase ROLLBACK
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.modelling.command.AbstractRepository$$Lambda$1249/0x00000008009c3840 for phase PREPARE_COMMIT
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : handling WithdrawMoneyCommand(accountID=f00088d7-c81a-432c-b010-28a88012f0eb, holderID=b232a9e8-d280-48bc-9d17-df03c9fe4071, amount=10)
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : applying WithdrawMoneyEvent(holderID=b232a9e8-d280-48bc-9d17-df03c9fe4071, accountID=f00088d7-c81a-432c-b010-28a88012f0eb, amount=10)
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : balance 370
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1260/0x00000008009c6440 for phase AFTER_COMMIT
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1261/0x00000008009c6840 for phase ROLLBACK
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1263/0x00000008009c7040 for phase PREPARE_COMMIT
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1264/0x00000008009c7440 for phase COMMIT
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1265/0x00000008009c7840 for phase AFTER_COMMIT
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1266/0x00000008009c7c40 for phase CLEANUP
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventsourcing.EventCountSnapshotTriggerDefinition$EventCountSnapshotTrigger$$Lambda$1245/0x00000008009c2840 for phase PREPARE_COMMIT
[nio-8080-exec-5] org.axonframework.messaging.Scope        : Clearing out ThreadLocal current Scope, as no Scopes are present
[nio-8080-exec-5] o.a.m.unitofwork.AbstractUnitOfWork      : Committing Unit Of Work
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase PREPARE_COMMIT
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.axonserver.connector.event.axon.AxonServerEventStore$AxonIQEventStorageEngine$$Lambda$1276/0x00000008009ce840 for phase ROLLBACK
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.axonserver.connector.event.axon.AxonServerEventStore$AxonIQEventStorageEngine$$Lambda$1277/0x00000008009cec40 for phase COMMIT
[nio-8080-exec-5] o.a.a.c.event.axon.AxonServerEventStore  : Reading events for aggregate id f00088d7-c81a-432c-b010-28a88012f0eb
[ault-executor-4] o.a.a.c.e.AxonServerEventStoreClient     : Done request for f00088d7-c81a-432c-b010-28a88012f0eb: 10ms, 4 events
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : >> applying AccountCreationEvent(holderID=b232a9e8-d280-48bc-9d17-df03c9fe4071, accountID=f00088d7-c81a-432c-b010-28a88012f0eb)
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : applying DepositMoneyEvent(holderID=b232a9e8-d280-48bc-9d17-df03c9fe4071, accountID=f00088d7-c81a-432c-b010-28a88012f0eb, amount=400)
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : balance 400
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : applying WithdrawMoneyEvent(holderID=b232a9e8-d280-48bc-9d17-df03c9fe4071, accountID=f00088d7-c81a-432c-b010-28a88012f0eb, amount=10)
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : balance 390
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : applying WithdrawMoneyEvent(holderID=b232a9e8-d280-48bc-9d17-df03c9fe4071, accountID=f00088d7-c81a-432c-b010-28a88012f0eb, amount=10)
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : balance 380
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : applying WithdrawMoneyEvent(holderID=b232a9e8-d280-48bc-9d17-df03c9fe4071, accountID=f00088d7-c81a-432c-b010-28a88012f0eb, amount=10)
[nio-8080-exec-5] c.c.command.aggregate.AccountAggregate   : balance 370
[nio-8080-exec-5] org.axonframework.messaging.Scope        : Clearing out ThreadLocal current Scope, as no Scopes are present
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase COMMIT
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase AFTER_COMMIT
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase CLEANUP
[nio-8080-exec-5] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase CLOSED
[ault-executor-4] o.a.a.c.event.axon.AxonServerEventStore  : Snapshot created

 왜 400 -> 370 까지 로그가 두 번 찍히는지는 모르겠지만 마지막에 snapshot created.

이 후 인출6 시 로그. 확실히 400 -> 370 까지 다시 하지 않고 바로 360으로 간다.

[nio-8080-exec-7] o.a.commandhandling.SimpleCommandBus     : Handling command [com.cqrs.command.commands.WithdrawMoneyCommand]
[nio-8080-exec-7] o.a.m.unitofwork.AbstractUnitOfWork      : Starting Unit Of Work
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.messaging.unitofwork.AbstractUnitOfWork$$Lambda$1192/0x000000080087ac40 for phase ROLLBACK
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase STARTED
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.messaging.unitofwork.UnitOfWork$$Lambda$1196/0x0000000800879c40 for phase COMMIT
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.messaging.unitofwork.UnitOfWork$$Lambda$1197/0x0000000800879040 for phase ROLLBACK
[nio-8080-exec-7] o.a.a.c.event.axon.AxonServerEventStore  : Reading events for aggregate id f00088d7-c81a-432c-b010-28a88012f0eb
[ault-executor-5] o.a.a.c.e.AxonServerEventStoreClient     : Done request for f00088d7-c81a-432c-b010-28a88012f0eb: 15ms, 1 events
[nio-8080-exec-7] org.axonframework.messaging.Scope        : Clearing out ThreadLocal current Scope, as no Scopes are present
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.modelling.command.LockingRepository$$Lambda$1246/0x00000008009c2c40 for phase CLEANUP
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.modelling.command.AbstractRepository$$Lambda$1247/0x00000008009c3040 for phase ROLLBACK
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.modelling.command.AbstractRepository$$Lambda$1249/0x00000008009c3840 for phase PREPARE_COMMIT
[nio-8080-exec-7] c.c.command.aggregate.AccountAggregate   : handling WithdrawMoneyCommand(accountID=f00088d7-c81a-432c-b010-28a88012f0eb, holderID=b232a9e8-d280-48bc-9d17-df03c9fe4071, amount=10)
[nio-8080-exec-7] c.c.command.aggregate.AccountAggregate   : applying WithdrawMoneyEvent(holderID=b232a9e8-d280-48bc-9d17-df03c9fe4071, accountID=f00088d7-c81a-432c-b010-28a88012f0eb, amount=10)
[nio-8080-exec-7] c.c.command.aggregate.AccountAggregate   : balance 360
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1260/0x00000008009c6440 for phase AFTER_COMMIT
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1261/0x00000008009c6840 for phase ROLLBACK
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1263/0x00000008009c7040 for phase PREPARE_COMMIT
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1264/0x00000008009c7440 for phase COMMIT
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1265/0x00000008009c7840 for phase AFTER_COMMIT
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.eventhandling.AbstractEventBus$$Lambda$1266/0x00000008009c7c40 for phase CLEANUP
[nio-8080-exec-7] org.axonframework.messaging.Scope        : Clearing out ThreadLocal current Scope, as no Scopes are present
[nio-8080-exec-7] o.a.m.unitofwork.AbstractUnitOfWork      : Committing Unit Of Work
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase PREPARE_COMMIT
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.axonserver.connector.event.axon.AxonServerEventStore$AxonIQEventStorageEngine$$Lambda$1276/0x00000008009ce840 for phase ROLLBACK
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Adding handler org.axonframework.axonserver.connector.event.axon.AxonServerEventStore$AxonIQEventStorageEngine$$Lambda$1277/0x00000008009cec40 for phase COMMIT
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase COMMIT
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase AFTER_COMMIT
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase CLEANUP
[nio-8080-exec-7] o.a.m.u.MessageProcessingContext         : Notifying handlers for phase CLOSED

그 이후로도 입금/출금 계속 했더니 위처럼 반복되다가 5번째마다 스냅샷이 잘 찍히는 것을 알 수 있다.


실패기록:

api를 몇 번 랜덤하게 쐈더니 아래와 같은 에러가 났다.

AxonServerException OUT_OF_RANGE: [AXONIQ-2000] Invalid sequence number while storing snapshot.

..왜 나에게만 이런 시련이

스택오버플로우에서 알려준대로 application.yml에 아래를 추가하고 재시작하니 해결되었다.. (하지만 그거시 아니었다..ㅎ)

axon:
    eventhandling:
        processors:
            name:
                mode: tracking

무슨 의미인지 찾아보던 중, 원문에 default가 tracking이라는데 저걸 또 명시하는게 무슨 의미인가 싶은데... 또 에러가 해결은 되고... ㅎ

Event Processors come in roughly two forms: Subscribing and Tracking. The Subscribing Event Processors subscribe themselves to a source of Events and are invoked by the thread managed by the publishing mechanism. Tracking Event Processors, on the other hand, pull their messages from a source using a thread that it manages itself.
...
By default, Axon will use Tracking Event Processors.

event processor 설명: https://cla9.tistory.com/15?category=814447 

 

11. Query 어플리케이션 구현(Event) - 1

1. 서론 이번 포스팅부터 Query App 구현을 다루겠습니다. Query App은 Event를 수신받아 Read Model에 반영하는 Projection 작업과 Read Model을 읽는 Query 2가지로 기능이 나뉩니다. 기능별로 실제 구현 코드..

cla9.tistory.com

 

아니, 해결된 줄 알고 또 몇 번 해보니 아래의 에러가 나온다. 구글링해도 뭐가 안 나온다.. 돌겠네..ㅋㅋㅋㅋ 

ConcurrencyException: OUT_OF_RANGE: [AXONIQ-2000] Invalid sequence number while storing snapshot.

 

내가 같은 holderId로 계좌 생성을 두번했는데, 서로 다른 계좌가 생성되긴 했지만,, 뭔가 그 후로 sequence 가 꼬인 듯.. 싶다.

무튼 저거 버리고 다시 처음부터 하니 그 후론 재연도 안된다 ㅎㅅㅎ;

 

궁금한게, 분명 axon server 안에서 저 이벤트/스냅샷을 저장하고 있다가 복기하는 것 같은데.. 어디에 있는지 모르겠다.

그걸 확인해서 꼬인 부분을 해결해보려고 했는데, 프로퍼티에 설정한 디비 테이블을 뒤져도 다 empty라서.. 어디에 저장하는지 궁금하다.

+ 찾아보니,

현재 구현 버전은 event-sourced-aggregate 이라하여 axon server의 event store에 저장하는 구현 방식이다. 즉 설정파일(axonserver.properties)에 지정한 경로에 파일로 각 이벤트를 저장하는 것이다. 

아래는 현재 내 axonserver의 설정과 데이터 값의 예시이다.

[root@localhost axonserver]# cat axonserver.properties 

logging.file=/var/log/axonserver/axonserver.log
logging.file.max-history=10
logging.file.max-size=10MB
axoniq.axonserver.event.storage=./events
axoniq.axonserver.snapshot.storage=./events
axoniq.axonserver.controldb-path=./data
-------------------------------------------------
[root@localhost default]# pwd
/var/lib/axonserver/events/default
[root@localhost default]# ll
-rw-r--r--. 1 axonserver axonserver 268435456  1월 18 17:11 00000000000000000000.events
-rw-r--r--. 1 axonserver axonserver 268435456  1월 18 17:11 00000000000000000000.snapshots

/// event 파일 예시

$a1fe8538-2955-4311-b371-b55811b5d1a1^R$f00088d7-c81a-432c-b010-28a88012f0eb^X^N"^PAccountAggregate(å<84><9d>áæ/2÷^A
"com.cqrs.events.WithdrawMoneyEvent^ZÐ^A<com.cqrs.events.WithdrawMoneyEvent><holderID>b232a9e8-d280-48bc-9d17-df03c9fe4071</holderID><accountID>f00088d7-c81a-432c-b010-28a88012f0eb</accountID><amount>10</amount></com.cqrs.events.WithdrawMoneyEvent>rW<96>^]^@^@^Ae^B^@^A^@^@^Aa

/// snapshot 파일 예시

$67179188-1d02-4a6a-ade3-49cd5586b88c^R$f00088d7-c81a-432c-b010-28a88012f0eb^X^H"^PAccountAggregate(<93>ñ<87>àæ/2<95>^B
+com.cqrs.command.aggregate.AccountAggregate^Zå^A<com.cqrs.command.aggregate.AccountAggregate><accountID>f00088d7-c81a-432c-b010-28a88012f0eb</accountID><holderID>b232a9e8-d280-48bc-9d17-df03c9fe4071</holderID><balance>740</balance></com.cqrs.command.aggregate.AccountAggregate>±C>Ò^@^@^A<84>^B^@^A^@^@^A<80>

 

위의 나의 궁금증을 해결하기 위해서는 다음 글에서 설명하는 (디비에 저장하는) state-stored-aggregate을 공부하면 될 듯 하다.


참고자료

설명

https://docs.axoniq.io/reference-guide/v/4.0/configuring-infrastructure-components/event-processing/event-processors

 

Event Processors - Axon Reference Guide

By default, exceptions that are raised by Event Handlers are logged, and processing continues with the next events. Exceptions that are thrown when a processor is trying to commit a transaction, update a token, or in any other other part of the process, th

docs.axoniq.io

boot 설정 값

https://docs.axoniq.io/reference-guide/v/3.3/part-iii-infrastructure-components/spring-boot-autoconfiguration

 

Spring Boot AutoConfiguration - Axon Reference Guide

To fully customize the repository used, you can define one in the Application Context. For Axon Framework to use this repository for the intended Aggregate, define the bean name of the repository in the repository attribute on @Aggregate Annotation. Altern

docs.axoniq.io

 

728x90
반응형

+ Recent posts