如何在嵌入模式下使用symmetricDS

时间:2015-08-29 22:08:32

标签: symmetricds

我有以下用例: 数据库A(主)和数据库B(从属),位于不同的机器上。 我想将数据库A与数据库B同步。 我想使用SymmetricDS embedded创建一个java应用程序。 由于没有关于如何执行此操作的文档,我想要一个示例示例或文档。 请帮帮我,我被卡住了。

2 个答案:

答案 0 :(得分:1)

这是一个如何在嵌入式模式下运行Symmetric engine server的例子,它对我来说是完美的:

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;
	}
}

主要课程:

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();
		}
				
	}

属性文件:

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

答案 1 :(得分:0)

文档中有关于将symmetricDs引擎嵌入Java SE应用程序的部分:http://www.symmetricds.org/doc/3.6/user-guide/html-single/user-guide.html#deployment-options-embedded

相关问题