-
Notifications
You must be signed in to change notification settings - Fork 0
9_Application Events and Listeners #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
nemoguigrat
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вообще выглядит интересно, но ничего не работает. Из за отсутствия транзакции дальше события не прокидываются и не обрабатываются
| public void handlePaymentSuccessEvent(PaymentProcessedEvent event) { | ||
| log.info("Handle PaymentProcessedEvent (AFTER_COMMIT)..."); | ||
| log.info("Publish OrderCreatedEvent."); | ||
| eventPublisher.publishEvent(new OrderCreatedEvent()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не обязательно публиковать. Можно сделать return этого события. Спринг сам его опубликует
| public class PaymentService { | ||
| private final ApplicationEventPublisher eventPublisher; | ||
|
|
||
| @Transactional(value = REQUIRES_NEW, rollbackOn = Exception.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я пробовал запускать проект и транзакция здесь не открывается даже с этими параметрами. Попробуй пересмотреть логику
| @Log4j2 | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class PaymentEventListener { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Точно такой же перехватчик находится в пакете org.javaspringcourse.order.eventListener. Зачем это нужно?
| @@ -0,0 +1,27 @@ | |||
| package org.javaspringcourse.payment.eventListener; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
пакеты в java лучше называть либо одним словом, либо без разделителей. eventlistener
Студент: Аптуликсанов Руслан Германович
Преподаватель: Никита Иванов
handleOrderCreatedEvent- обычный,handleOrderCreatingEvent- async, классыPaymentProcessedEventListenerиPaymentEventListener- содержат TransactionalEventListener)PaymentProcessedEventListenerиPaymentEventListenerс помощью фаз AFTER_COMMIT и AFTER_ROLLBACK)В этом задании я попытался реализовать связь двух условных микросервисов OrderService и PaymentService через события и обработчики (в каждом сервисе стоят обработчики на события другого сервиса) (поэтому листенеров чуть больше, чем в условии).