{"id":16619938,"url":"https://github.com/cepr0/sb-reactive-transaction-publishing-event-issue","last_synced_at":"2026-05-09T07:33:15.679Z","repository":{"id":130472720,"uuid":"191242596","full_name":"Cepr0/sb-reactive-transaction-publishing-event-issue","owner":"Cepr0","description":"Issue with the behavior of the 'event listener' methods when events are published within the transactional reactive methods in Spring Boot 2.2.0.M3","archived":false,"fork":false,"pushed_at":"2019-07-12T10:28:34.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-17T22:09:10.962Z","etag":null,"topics":["reactive","spring","spring-boot","transactions"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Cepr0.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-10T20:42:07.000Z","updated_at":"2019-07-12T10:28:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"5d13b985-2d75-4493-995c-1dca8627cbee","html_url":"https://github.com/Cepr0/sb-reactive-transaction-publishing-event-issue","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cepr0%2Fsb-reactive-transaction-publishing-event-issue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cepr0%2Fsb-reactive-transaction-publishing-event-issue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cepr0%2Fsb-reactive-transaction-publishing-event-issue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cepr0%2Fsb-reactive-transaction-publishing-event-issue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cepr0","download_url":"https://codeload.github.com/Cepr0/sb-reactive-transaction-publishing-event-issue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242988166,"owners_count":20217554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["reactive","spring","spring-boot","transactions"],"created_at":"2024-10-12T02:43:08.715Z","updated_at":"2025-12-24T07:49:11.549Z","avatar_url":"https://github.com/Cepr0.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"This demo demonstrates the issue with the behavior of the 'event listener' methods \nwhen events are published within the transactional reactive methods \nin Spring Boot 2.2.0.M3.\n\n**Sample reactive method**\n\n```java\n@Transactional\npublic Mono\u003cModel\u003e create(Model model, ModelEvent.Type type) {\n    return repo.save(model)\n            .doOnSuccess(m -\u003e publisher.publishEvent(new ModelEvent(m, type)));\n}\n```\n\n**Normal behavior**\n\nThe following code works as expected. The method is invoked within the current transaction -\nif we uncomment the throwing the exception then the current transaction will be rolled back.\n\n```java\n@EventListener(condition = \"#event.normal()\")\npublic void handleNormalEvent(ModelEvent event) {\n    log.info(\"[i] Handled event: {}\", event.getModel());\n    // throw new RuntimeException(\"Oops, something went wrong...\");\n}\n```  \n\n**IllegalStateException is raised**\n\nIf we add `@Transactional` annotation with `MANDATORY` propagation parameter to check that \nthe 'event listener' method is invoked in the existent transaction, \nthen the `IllegalStateException` is raised with a message: \n`Specified transaction manager is not a PlatformTransactionManager: \norg.springframework.data.mongodb.ReactiveMongoTransactionManager`  \n\n```java\n@Transactional(propagation = Propagation.MANDATORY)\n@EventListener(condition = withTransactional)\npublic void handleEventWithTransactional(ModelEvent event) {\n    log.info(\"[i] Handled event: {}, with transactional\", event.getModel());\n}\n```\n\n**@TransactionalEventListener**\n\nIf we use `@TransactionalEventListener` (instead of `@EventListener`) then \nthe 'event listener' method is not invoked at all.   \n\n```java\n// @Async\n@TransactionalEventListener(condition = \"#event.inTransactionEventListener()\")\npublic void handleEventInTransactionEventListener(ModelEvent event) {\n    log.info(\"[i] Handled event: {}, in transactional event listener\", event.getModel());\n}\n```       \n\n**Reproducing the issue**\n\n1) Start a MongoDB Replica Set cluster (within the project folder)\n```bash\ndocker-compose up -d\n```\n\n2) Start the application\n```bash\nmvn spring-boot:run\n```\n\n(or you can start cluster simply with the application: `mvn spring-boot:run -Dspring.profiles.active=replSet`)\n\n3) Run the requests from the `demo-requests.http` file \n\n(or you can run the application and requests within Intellij IDEA)\n\n4) Don't forget to stop the cluster if you explicitly start it\n```bash\ndocker-compose down\n```\n\nOr you can check the [`ModelHandlerTest`](src/test/java/io/github/cepr0/issue/ModelHandlerTest.java) class.\n\n**Requirements**\n\nDocker, Docker Compose, Java 8, Maven\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcepr0%2Fsb-reactive-transaction-publishing-event-issue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcepr0%2Fsb-reactive-transaction-publishing-event-issue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcepr0%2Fsb-reactive-transaction-publishing-event-issue/lists"}