Open znaczek opened 1 week ago
the goal is to have separate
event_publication
table for every module db schema.
That has been a non-goal so far. I wonder how / whether this would work reasonably well in practice. Primarily because the listener decoration would need to know which schema to use to mark the publication completed. This logically ties the two transactions anyway (the publishing one and the consuming one). What is supposed to happen if the publishing transaction is running against the DataSource
for schema one, but a listener is declared to run on schema two?
Is it an option to rather use one DataSource
and assign the individual entities to dedicated schemas via @Table(schema = …)
?
I see the @Table
annotation works for you. You should be able to override the schema for the EventPublication
JPA entity in orm.xml
. In JPA we have little influence on any mapping customizations that you might want to apply. I wonder if it makes sense to add a property to the JDBC implementation that'd allow defining a custom schema to be used for that table.
I have an application with two
@ApplicationModule
:orders
andproducts
. I want to have a separate PostgreSQL schema for each of them usingspring-boot-starter-data-jpa
. That's how I achieved the desired configuration.TransactionManagers
setup:and
I configure them with the following properties file:
With the above setup application (without Event Publication Registry configured yet) works correctly.
I added
spring-modulith-starter-jpa
, made use of@TransactionalEventListere
and created theevent_publication
table according to the documentation in both schemas - the goal is to have separateevent_publication
table for every module db schema.When I tested it, I was getting the following error when dispatching an event using
ApplicationEventPublisher
:As I understand, this is cause by #JpaEventPublicationConfiguration#jpaEventPublicationRepository accepts
EntityManager em
without any@Qualifier
and my setup doesn't provide one.So I tried to add
@Primary
to one of the qualified TransacitonManagers (this is against the goal above, but at least I want to try it that helps), but then I was getting another error:which looks similar to #345. However, when I try to follow the suggestion and add
org.springframework.modulith.events.jpa
to@EntityScan
like this:It doesn't help in my case.
A also tried using
spring-modulith-starter-jdbc insted
instead. At the beginning it was throwing the sameNo qualifying bean
exception. I tried again to add@Primary
to one of theTransactionManagers
. But the the result was quite strange - events were stored inorders.event_publication
regardless of on whichTransactionManager
bean I was putting@Primary
(🤯).At this point I am running out of ideas... Thanks for any help!
EDIT After a while I tried with the default
DataSource
andTransactionManager
(autoconfigured by Spring) and I defined the schema in@Table
annotation. That worked, however with this I had to define singleevent_publication
inpublic
schema. Still have no workaround for working with separateTransactionManagers