This is a collection of Docker environments demonstrating Db2 failover options with Liberty. It consists of a simple Servlet application which returns the JDBC url of the database it's connection points to, and a pair of Db2 containers for failover.
Db2 client reroute is the simplest failover option, allowing rerouting to occur only on the first connection request.
-
Build the application and start the containers
./gradlew libertyPackage && docker-compose -f reroute.yml build && docker-compose -f reroute.yml up
-
After all containers have completed initializing, access the endpoint
http://localhost:9080/liberty-db2-acr/example
It should point to thedb2b
container
URL:jdbc:db2://db2b:50000/TESTDB
-
Stop the containers and uncomment the the db2a container in
reroute.yml
-
Build and start the containers again
docker-compose -f reroute.yml build && docker-compose -f reroute.yml up
-
After all containers have completed initializing, access the endpoint
http://localhost:9080/liberty-db2-acr/example
It should point to thedb2a
container
URL:jdbc:db2://db2a:50000/TESTDB
Client affinities allows for failover at runtime, on new connection requests.
-
Build the application and start the containers
./gradlew libertyPackage && docker-compose -f client-affinities.yml build && docker-compose -f client-affinities.yml up
-
After all containers have completed initializing, access the endpoint
http://localhost:9080/liberty-db2-acr/example
It should point to thedb2a
container
URL:jdbc:db2://db2a:50000/TESTDB
-
Stop the db2a container
docker stop liberty-db2-acr-db2a-1
-
Access the endpoint
http://localhost:9080/liberty-db2-acr/example
It should point to thedb2b
container
URL:jdbc:db2://db2b:50000/TESTDB
-
Restart the db2a container
docker start liberty-db2-acr-db2a-1
-
After the container has completed initializing, access the endpoint
http://localhost:9080/liberty-db2-acr/example
Failback should have occurred, so it should point to thedb2a
container
URL:jdbc:db2://db2a:50000/TESTDB