https://github.com/kh77/spring-boot-multi-db
Distributed transaction using mysql and postgres
https://github.com/kh77/spring-boot-multi-db
java mysql postgres spring-boot
Last synced: 3 months ago
JSON representation
Distributed transaction using mysql and postgres
- Host: GitHub
- URL: https://github.com/kh77/spring-boot-multi-db
- Owner: kh77
- Created: 2020-07-12T20:58:12.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-04T19:04:10.000Z (about 4 years ago)
- Last Synced: 2023-03-06T22:09:10.140Z (over 3 years ago)
- Topics: java, mysql, postgres, spring-boot
- Language: Java
- Homepage:
- Size: 53.7 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# spring-boot-multiple-db
Register multiple DB like MySql and PostgreSql and how to handle distributed transaction of multiple DB and roll-back.
## Database script
1) MySQL Script and (FooDbConfig.java) which has configuration
CREATE schema foo;
CREATE TABLE foo.foo_data
( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(45) NULL, PRIMARY KEY (id));
--------------------------------------------
2) PostgreSQL Script and (BarDbConfig.java) which has configuration with bar prefix in application.properties
CREATE DATABASE bar
WITH
OWNER = postgres
ENCODING = 'UTF8'
CONNECTION LIMIT = -1;
CREATE TABLE public.bar_data
(
id bigserial,
name character varying(500),
PRIMARY KEY (id)
)
WITH (
OIDS = FALSE
);
ALTER TABLE public.bar_data
OWNER to postgres;
-----------------------------------------------------------
# Manage Multiple DB transaction and roll-back
This 'ChainedTransactionManagerConfig' class register both transaction manager DB and it will roll-back when one transaction is failed
Check 'FooService' class which has 'insert' method and hit below URL to save data
-----------------------------------------------------------
## URL to save data from Postman
- Save data in both DB
- Http Method : GET
- URL : localhost:8080/save/helloworld
- Response body : OK
## Uncomment RuntimeException from BarService.java
- try above url then it will roll-back both transaction