问题描述
我正在尝试在使用H2数据库的Java应用程序中嵌入对称 3.7.该应用程序是一个客户端节点,并使用SymmetricDS API中的类ClientSymmetricEngine
.
I'm trying to embedded Symmetricds 3.7 in a java application which uses H2 database. The application is a client node and uses the class ClientSymmetricEngine
from SymmetricDS API.
主节点运行独立的对称服务器,当我使用应用程序中先前测试中已配置的数据库时,我能够同步数据.
The master node runs standalone symmetricds server and I was able to synchronize the data when I used an already configured databsae from previous tests in the application.
在新数据库上运行应用程序时,它将引发以下异常:
When running the application on a new database, it throws this exception:
java.lang.IllegalStateException: This node has not been configured.Could not find a row in the identity table
at
org.jumpmind.symmetric.service.impl.RegistrationService.openRegistration(RegistrationService.java:562)
at
org.jumpmind.symmetric.service.impl.RegistrationService.openRegistration(RegistrationService.java:530)
at
org.jumpmind.symmetric.service.impl.RegistrationService.openRegistration(RegistrationService.java:519)
at
org.jumpmind.symmetric.AbstractSymmetricEngine.openRegistration(AbstractSymmetricEngine.java:890)
at syncdemo.ClientNode.<init>(ClientNode.java:32)
at syncdemo.SyncDemo.main(SyncDemo.java:37)
如何通过API在客户端节点中创建SYM表?
How do I create SYM Tables in the client node through the API?
我从此处获得了用于同步的代码.在ClientNode类中使用的方法如下:
I got the code for syncing from here. Which is being used in the ClientNode class as follows:
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("store", "001");
getcEngine().setup();
getcEngine().start();
}
public ClientSymmetricEngine getcEngine() {
return cEngine;
}
public void setcEngine(ClientSymmetricEngine cEngine) {
this.cEngine = cEngine;
}
}
从此处调用clientNode类:
Calling clientNode class from here:
public class SyncDemo {
public static void main(String[] args) {
try
{
new ClientNode(new File("/client.properties"));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
client.properties文件的内容:
Content of client.properties file:
external.id=001
engine.name=store-001
sync.url=http://192.168.1.107:31415/sync/corp-000
group.id=store
db.url=jdbc:h2:./syncdata/store001;AUTO_SERVER=TRUE;LOCK_TIMEOUT=60000
db.driver=org.h2.Driver
db.user=symmetric
registration.url=http://192.168.1.107:31415/sync/corp-000
db.password=
auto.config.database=true
我刚刚注意到,即使客户端节点数据库中存在SYM表,也将引发相同的异常,除非在SYM_NODE和SYM_NODE_IDENTITY表中插入了适当的数据.
I just noticed that even if the SYM Tables are present in the client node's database, same exception is thrown unless appropriate data is inserted in SYM_NODE and SYM_NODE_IDENTITY tables.
推荐答案
接受的答案对我不起作用,我仍然遇到相同的错误.我结合了已接受答案中的更改以及理解,一起工作了:
The accepted answer did not work for me, I still got the same error. I got it working with a combination of the change in the accepted answer, plus understanding:
- 每个客户端节点上的sync.url在注册时来自服务器.
- registration.url告诉客户端节点在哪里可以找到配置(主)节点.
- 如果您过去曾经搞砸过任何一个,则sym_表中的某些内容将被弄乱.您最好清除数据库并重新启动.
- 不会在嵌入式应用程序中自动填充sym_表.您必须手动填充它们.
.../samples/insert_sample.sql
文件是您的朋友.
- the sync.url on each client node comes from the server at registration time.
- the registration.url tells the client nodes where to find the configuration (master) node.
- If you've ever screwed either of those up in the past, something in your sym_ tables is messed up. You're probably better off wiping your database and starting again.
- the sym_ tables are not auto-populated for you in an embedded app. You must manually populate them. The
.../samples/insert_sample.sql
file is your friend.
这篇关于在SymmetricDS Embedded中创建SYM表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!