Skip to content

Event expected to arrive in integration test never arrives #204

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

Closed
splatter0 opened this issue May 15, 2023 · 4 comments
Closed

Event expected to arrive in integration test never arrives #204

splatter0 opened this issue May 15, 2023 · 4 comments
Assignees
Labels
in: event publication registry Event publication registry resolution: works as designed This is expected behavior

Comments

@splatter0
Copy link

splatter0 commented May 15, 2023

I met a problem when i'm using spring-modulith-events in a project, example detailed as below:
https://github.com/xjianyu/spring-modulith-events-example/blob/main/src/test/java/com/example/order/OrderTests.java

@splatter0
Copy link
Author

splatter0 commented May 15, 2023

create order then pay order, pay order cannot be executed

image

@splatter0
Copy link
Author

splatter0 commented May 16, 2023

@Transactional
@TransactionalEventListener
public void onOrderCreated(OrderCreated event) {
log.info("order created {}", event.getId());
orderPaidService.pay(event.getId());
}

change into

@Transactional(propagation = Propagation.REQUIRES_NEW)
@TransactionalEventListener
public void onOrderCreated(OrderCreated event) {
log.info("order created {}", event.getId());
orderPaidService.pay(event.getId());
}

It will be ok.

@odrotbohm
Copy link
Member

As transactional event listeners are invoked during the transaction cleanup phase, marking them as @Transactional will not have the effect of actually running the method in a transactional way. Thus, and as you already have discovered, you will need to use Propagation.REQUIRES_NEW. This is one of the reasons @ApplicationModuleListener exists, as it sets up a transactional event listener with a new transaction.

I'll take this forward to the team to debate whether we can detect such a misconfiguration and report the problem to users in a reasonable way.

@odrotbohm odrotbohm self-assigned this Jun 1, 2023
@odrotbohm odrotbohm added in: event publication registry Event publication registry meta: investigating Stuff that needs more investigation labels Jun 1, 2023
@odrotbohm odrotbohm changed the title spring-modulith-events not work Event expected to arrive in integration test never arrives Jun 13, 2023
@odrotbohm odrotbohm added resolution: works as designed This is expected behavior and removed meta: investigating Stuff that needs more investigation labels Jun 15, 2023
@odrotbohm
Copy link
Member

I've filed spring-projects/spring-framework#30679 to make sure Spring Framework already detects that misconfiguration on application startup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: event publication registry Event publication registry resolution: works as designed This is expected behavior
Projects
None yet
Development

No branches or pull requests

2 participants