2022.01.18 - [개발/spring] - [axon] snapshot - clone coding
저번 글에 이어서 state stored aggregate 방식에 대해 알아본다.
클론 코딩 참고 블로그는 다음와 같다: https://cla9.tistory.com/13?category=814447
state store aggregate 으로 전환하고 실행, api 쏴보니 아래와 같은 jpa 에러가 난다.
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.cqrs.command.aggregate.HolderAggregate.accounts, could not initialize proxy - no Session
fetch type을 eager로 바꾼다.
@OneToMany(mappedBy = "holder", orphanRemoval = true, fetch = FetchType.EAGER)
private List<AccountAggregate> accounts = new ArrayList<>();
참고: https://ankonichijyou.tistory.com/entry/JPA-OneToMany-%EC%98%A4%EB%A5%98
다시 하는데 아래와 같은 에러가 난다... 열심히 구글링했는데 별다른 힌트를 얻지 못해서.. axonserver 를 재시작했는데.. 세상에 잘 된다..
(설정을 변경해보려다 실패해서 얻어걸린 재시작 ㅎ) .. 내 2시간..ㅎ
2022-01-19 14:15:50.006 WARN 6587 --- [ault-executor-3] o.a.a.c.u.ResubscribableStreamObserver : A problem occurred in the stream.
io.grpc.StatusRuntimeException: CANCELLED: HTTP/2 error code: CANCEL
Received Rst Stream
..
Hibernate: insert into account (balance, holder_id, account_id) values (?, ?, ?)
2022-01-19 14:15:50.010 ERROR 6587 --- [nio-8080-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] threw exception
org.axonframework.axonserver.connector.command.AxonServerCommandDispatchException: CANCELLED: HTTP/2 error code: CANCEL
Received Rst Stream
...
2022-01-19 14:15:50.010 ERROR 6587 --- [nio-8080-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is AxonServerCommandDispatchException{message=CANCELLED: HTTP/2 error code: CANCEL
Received Rst Stream, errorCode='AXONIQ-4003', server='6587@AL01590036.local'}] with root cause
org.axonframework.axonserver.connector.command.AxonServerCommandDispatchException: CANCELLED: HTTP/2 error code: CANCEL
Received Rst Stream
...
2022-01-19 14:35:34.782 WARN 6587 --- [ault-executor-7] o.a.a.c.u.ResubscribableStreamObserver : A problem occurred in the stream.
io.grpc.StatusRuntimeException: UNAVAILABLE: HTTP/2 error code: NO_ERROR
Received Goaway
app_requested
hibernate sql log가 지나간다.
Hibernate: insert into holder (address, holder_name, tel, holder_id) values (?, ?, ?, ?)
---
Hibernate: select holderaggr_.holder_id, holderaggr_.address as address2_2_, holderaggr_.holder_name as holder_n3_2_, holderaggr_.tel as tel4_2_ from holder holderaggr_ where holderaggr_.holder_id=?
Hibernate: insert into account (balance, holder_id, account_id) values (?, ?, ?)
---
Hibernate: select accountagg0_.account_id as account_1_0_0_, accountagg0_.balance as balance2_0_0_, accountagg0_.holder_id as holder_i3_0_0_ from account accountagg0_ where accountagg0_.account_id=? for update
Hibernate: select holderaggr0_.holder_id as holder_i1_2_0_, holderaggr0_.address as address2_2_0_, holderaggr0_.holder_name as holder_n3_2_0_, holderaggr0_.tel as tel4_2_0_, accounts1_.holder_id as holder_i3_0_1_, accounts1_.account_id as account_1_0_1_, accounts1_.account_id as account_1_0_2_, accounts1_.balance as balance2_0_2_, accounts1_.holder_id as holder_i3_0_2_ from holder holderaggr0_ left outer join account accounts1_ on holderaggr0_.holder_id=accounts1_.holder_id where holderaggr0_.holder_id=?
Hibernate: update account set balance=?, holder_id=? where account_id=?
---
db를 봐도 잘 들어가 있다.
event sourced aggregate 방식과 다르게 매 스탭의 결과를 디비에 저장하기 때문에 매번 작업을 새롭게 하지 않는다는 장점이 있으나, 디비 연결에 대한 네트워크 이슈(속도), 디비가 날아가면 히스토리를 알기 어려움 등의 단점도 알아둬야겠다.
디비에 저장하면서 이벤트 발생 히스토리도 별도로 저장하면 좋지 않을까?
추가)
다시 소스를 보니 @CommandHandler 어노테이션만 있으면 별도의 repository나 save 등의 액션이 없이도 디비에 수정사항이 생기고 변화하는 것을 알 수 있다.
원문을 보면 아래와 같은 문구를 확인할 수 있다. 없으면 자동 생성해서 해주는 듯 하다.
Axon will automatically register all the @CommandHandler annotated methods with the command bus
and set up a repository if none is present.
또한 각 aggregate에 repository를 명시할 수도 있다.
@Aggregate(repository = "repositoryForGiftCard")
'개발 > axon framework' 카테고리의 다른 글
[axon] event upcasting - clone coding (0) | 2022.02.04 |
---|---|
[axon] query/replay 성능개선 - clone coding (0) | 2022.01.25 |
[axon] query/replay - clone coding (0) | 2022.01.24 |
[axon] snapshot - clone coding (0) | 2022.01.18 |
[axon] command/query project 생성 - clone coding (0) | 2022.01.12 |