连接到远程heroku实例时neo4j休息graphdb挂起 [英] neo4j rest graphdb hangs when connecting to remote heroku instance
问题描述
public class Test
{
private static RestAPI rest = new RestAPIFacade(myIp,username,password);
public static void main(String [] args)
{
Map< String,Object> foo = new HashMap< String,Object>();
foo.put(Test key,testing);
rest.createNode(foo);
}
}
没有输出,只能连接无限期地挂起。
环境:
Eclipse
JDK 7
neo4j-rest-binding 1.9: https://github.com/neo4j/java-rest-binding
Heroku
任何想法为什么这只是挂起?
以下代码工作:
public class Test b $ b {
为您的JVM。请注意,这可能会影响性能,因为每个原子操作都是单独的REST请求。
private static RestAPI rest = new RestAPIFacade(myIp,username,password);
public static void main(String [] args)
{
Node node = rest.getNodeById(1);
$ b $ p
$ b因此它表明我可以正确地检索远程值。解决方案我想这是由于交易的使用不足造成的。默认情况下,neo4j-rest-binding将多个操作合并成一个请求(又名一个事务)。有两种方法可以解决这个问题:通过设置
<$
$ b
- 将交易行为更改为1操作= 1交易 c $ c> -Dorg.neo4j.rest.batch_transaction = false
RestGraphDatabse db = new RestGraphDatabase(http:// localhost:7474 / db / data ,用户名密码);
Transaction tx = db.beginTx();
尝试{
Node node = db.createNode();
node.setPropery(key,value);
tx.success();
} finally {
tx.finish();
}
public class Test
{
private static RestAPI rest = new RestAPIFacade("myIp","username","password");
public static void main(String[] args)
{
Map<String, Object> foo = new HashMap<String, Object>();
foo.put("Test key", "testing");
rest.createNode(foo);
}
}
No output it just hangs on connection indefinitely.
Environment:
Eclipse
JDK 7
neo4j-rest-binding 1.9: https://github.com/neo4j/java-rest-binding
Heroku
Any ideas as to why this just hangs?
The following code works:
public class Test
{
private static RestAPI rest = new RestAPIFacade("myIp","username","password");
public static void main(String[] args)
{
Node node = rest.getNodeById(1);
}
}
So it stands that I can correctly retrieve remote values.
I guess this is caused by lacking usage of transactions. By default neo4j-rest-binding aggregates multiple operations into one request (aka one transaction). There are 2 ways to deal with this:
- change transactional behaviour to "1 operation = 1 transaction" by setting
-Dorg.neo4j.rest.batch_transaction=false
for your JVM. Be aware this could impact performance since every atomic operation is a seperate REST request. - use transactions in your code:
.
RestGraphDatabse db = new RestGraphDatabase("http://localhost:7474/db/data",username,password);
Transaction tx = db.beginTx();
try {
Node node = db.createNode();
node.setPropery("key", "value");
tx.success();
} finally {
tx.finish();
}
这篇关于连接到远程heroku实例时neo4j休息graphdb挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!