Search code examples
symmetricds

How to use symmetricDS in Embedded mode


I have the following use case: A database A (Master) and a database B (slave), located on diferent machines. I want to synchronize the Database A with Database B. I want to create a java application using SymmetricDS embedded. As there is no documentation on how to perform this, i want a sample example or a documentation . Please help me I'm stuck.


Solution

  • this an example how run the Symmetric engine server in embedded mode , and it works perfectley for me :

    public class ClientNode {
    	private ClientSymmetricEngine cEngine;
    	private File propFile;
    
    
    	public ClientNode(File file) throws FileNotFoundException, IOException {
    		propFile = file;
    		Properties propertiesFile = new Properties();
    		propertiesFile.load(new FileReader(propFile));
    		cEngine = new ClientSymmetricEngine(propertiesFile, true);
    		getcEngine().openRegistration("client", "001");// client is the name of the node group and 001 is the ID
    		getcEngine().setup();
    		getcEngine().start();
    	}
    
    	public ClientSymmetricEngine getcEngine() {
    		return cEngine;
    	}
    
    	public void setcEngine(ClientSymmetricEngine cEngine) {
    		this.cEngine = cEngine;
    	}
    }

    Main class :

    public static void main(String[] args) {
    	
    				
    	try {
    		new ClientNode(new File("client.properties"));
    		SymmetricWebServer node = new SymmetricWebServer("master.properties");
    		node.setWebAppDir("Web"); 
    		node.setJoin(false);
    		node.start();
    		// this will stop the node
    		//node.stop();
    		}catch (Exception e) {
    			e.printStackTrace();
    		}
    				
    	}

    Properties files :

    client.properties :

    external.id=001
    engine.name=client-001
    sync.url=http\://localhost\:31415/sync/client-001
    group.id=client
    db.url=jdbc\:mysql\://localhost/easyexchangedb_slave
    db.driver=com.mysql.jdbc.Driver
    db.user=root
    registration.url=http\://localhost\:31415/sync/server
    db.password=
    

    master.properties :

    external.id=server
    engine.name=server
    sync.url=http\://localhost\:31415/sync/server
    group.id=server
    db.url=jdbc\:mysql\://localhost/easyexchangedb_master
    db.driver=com.mysql.jdbc.Driver
    db.user=root
    registration.url=http\://localhost\:31415/sync/server
    db.password=
    auto.registration=true