How to use symmetricDS in Embedded mode

大兔子大兔子 提交于 2019-12-08 11:33:42

问题


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.


回答1:


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



回答2:


There's a section in the documentation about embedding symmetricDs engine into Java SE application: http://www.symmetricds.org/doc/3.6/user-guide/html-single/user-guide.html#deployment-options-embedded



来源:https://stackoverflow.com/questions/32291129/how-to-use-symmetricds-in-embedded-mode

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!