admin管理员组文章数量:1194371
We save information in a database using JPA repository functions. In our case we use saveAndFlush
to write our Entity into the database.
After that we are performing an HTTP request to another service. The response arrives asynchronously which means the service we called will call an endpoint of our service to return the response. After the response arrived we load our entity from the database to update its informations with data from the response. This works.
Hoever, as soon as we have more than one instance of our service running at the same time and have a proper load balancing it won't work any more. If the same instance which performed the HTTP request gets the response it is still working. But if instance A saves the data into the database and performs the HTTP request and instance B gets the callbabck and tries to load the data from the datababse, very often, the data isn't there. We have some kind of race condition. If the callback would arrive like 300 milliseconds later the data would be there.
We have tried any @Transactional
combination regarding isolation
and propagation existing without making the result any better or any worse.
How can we make sure that the data is actually written into the database before we perform our HTTP request?
本文标签: springHow to actually force a write into the databaseStack Overflow
版权声明:本文标题:spring - How to actually force a write into the database? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738501329a2090286.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论