如何在嵌入式模式下使用对称DS [英] How to use symmetricDS in Embedded mode
问题描述
我有以下用例: 位于不同计算机上的数据库A(主数据库)和数据库B(从属数据库). 我想将数据库A与数据库B同步. 我想使用嵌入式SymmetricDS创建一个Java应用程序. 由于没有有关如何执行此操作的文档,因此我需要一个示例示例或文档. 请帮助我,我被卡住了.
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.
推荐答案
这个示例说明了如何在嵌入式模式下运行对称引擎服务器,并且对我来说很完美:
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;
}
}
主类:
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:
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:
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
这篇关于如何在嵌入式模式下使用对称DS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!