This sample starts in replica mode and tries to connect to a master up to 3 times. If it fails to connect or the master dies, then it switches to master mode. In the master mode it initializes the database if necessary and then updates random records for 10 seconds
In a console window run:
RplMstThen in a second console window run the following, where
connect_string
is thehost:port
combination (localhost:10000
by default):RplMst <connect_string>Break the first instance with
Ctrl+C
. The second instance will automatically switch to master mode.Run the first instance again. It will connect to the second instance as replica.
But it is more instructive to run one instance in your development environment debugger, stepping through the code.