0

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

4

2 回答 2

3

这是一个如何在嵌入式模式下运行对称引擎服务器的示例,它对我来说非常有效:

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

属性文件:

客户端属性:

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=

主属性:

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
于 2015-09-02T10:44:48.003 回答
0

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

于 2015-08-31T09:38:14.997 回答