如何使用Java API获取Neo4j集群状态

时间:2018-12-10 18:05:23

标签: neo4j java-api

我正在尝试使用Java API查找neo4j集群的运行状况。我看到CLI CALL dbms.cluster.overview()是否有与此等效的Java api

1 个答案:

答案 0 :(得分:0)

1。变体“ Spring Boot”

如果带有Spring Data Neo4J的Spring Boot是您的选择,则可以定义一个DAO,该DAO执行cypher语句并在自己的QueryResult类中接收结果。

1.1 GeneralQueriesDAO

@Repository
public interface GeneralQueriesDAO extends Neo4jRepository<String, Long> {    
    @Query("CALL dbms.cluster.overview() YIELD id, addresses, role, groups, database;")
    ClusterOverviewResult[] getClusterOverview();
}

1.2 ClusterOverviewResult

@QueryResult
public class ClusterOverviewResult {
    private String id;  // This is id of the instance.
    private List<String> addresses; // This is a list of all the addresses for the instance.
    private String role; // This is the role of the instance, which can be LEADER, FOLLOWER, or READ_REPLICA.
    private List<String> groups; // This is a list of all the server groups which an instance is part of.
    private String database; // This is the name of the database which the instance is hosting.

    // omitted default constructor as well getter and setter for clarity    
} 

1.3程序流程

@Autowired
private GeneralQueriesDAO generalQueriesDAO;

[...]

ClusterOverviewResult[] clusterOverviewResult = generalQueriesDAO.getClusterOverview();

2。变体“无春”

没有Spring Boot,粗略的过程可能是:

Session session = driver.session();
StatementResult result = session.run("Cypher statement");

3。各种“ HTTP端点”

另一种选择是使用HTTP endpoints for monitoring the health of a Neo4j Causal Cluster