Skip to content

How can I get the Modulith event publication id if an exception is thrown by the method annotated with @ApplicationModuleListener? #405

Answered by dustinsand
dustinsand asked this question in Q&A
Discussion options

You must be logged in to vote

Found a way with Modulith 1.1.0 by implementing a org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler.AsyncUncaughtExceptionHandler used by a org.springframework.scheduling.annotation.AsyncConfigurer. The handleUncaughtException finds the TargetEventPublication by calling EventPublicationRepository.findIncompletePublicationsByEventAndTargetIdentifier passing the original event and the listener_id for the listener that handled the event.

@Override
  public void handleUncaughtException(
      Throwable throwable, Method method, Object @NotNull ... params) {
    // Only handle exception if from a method annotated with Modulith's @ApplicationModuleListener.
    // Listener will …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dustinsand
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant