How can I get the Modulith event publication id if an exception is thrown by the method annotated with @ApplicationModuleListener? #405
-
My use case is to write the exception thrown by a Listener annotated with @ApplicationModuleListener to a custom table, event_publication_event_publication_retry_history that has a foreign key to Modulith's event_publication.id column. This table is part of of our custom retry library for Modulith so developers can find the cause of the event failure when troubleshooting is required after the retry limit for the event has been exceeded. CREATE TABLE IF NOT EXISTS event_publication_retry_history Is there a way to add an interceptor as part of Moduliths handling of the failed event to hook into to write the exception to this table too? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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.
This works, but is there a better way to solve this use case? |
Beta Was this translation helpful? Give feedback.
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.