neo4j rest graphdb hangs when connecting to remote heroku instance

非 Y 不嫁゛ 提交于 2019-12-13 07:03:58

问题


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.


回答1:


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:

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


来源:https://stackoverflow.com/questions/14924284/neo4j-rest-graphdb-hangs-when-connecting-to-remote-heroku-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!