Created
August 17, 2018 22:36
-
-
Save AO-StreetArt/047a2b254e5e1f0f3ca685fe1a03dbfc to your computer and use it in GitHub Desktop.
Libneo4j-client - Viewing Cluster Nodes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <neo4j-client.h> | |
#include <errno.h> | |
#include <stdio.h> | |
int main(int argc, char *argv[]) { | |
//Pull the connection string | |
char *connection_string; | |
if (argc > 1) { | |
connection_string = argv[1]; | |
} else { | |
connection_string = "bolt://localhost:7687"; | |
} | |
// Start the Neo4j Connection | |
neo4j_client_init(); | |
neo4j_connection_t *connection = neo4j_connect(connection_string, NULL, NEO4J_INSECURE); | |
if (!connection) { | |
neo4j_perror(stderr, errno, "Connection failed"); | |
return EXIT_FAILURE; | |
} | |
// Execute the query which fetches the routing table | |
neo4j_result_stream_t *results = neo4j_run(connection, "CALL dbms.cluster.routing.getServers()", neo4j_null); | |
if (!results) { | |
neo4j_perror(stderr, errno, "Failed to run statement"); | |
return EXIT_FAILURE; | |
} | |
// Access the results of the query | |
neo4j_result_t *result = neo4j_fetch_next(results); | |
if (!result) { | |
neo4j_perror(stderr, errno, "Failed to fetch result"); | |
return EXIT_FAILURE; | |
} | |
// The first field has the key 'ltl' and I think it's a status/error code? | |
neo4j_value_t value = neo4j_result_field(result, 0); | |
char buf[8]; | |
printf("%s\n", neo4j_tostring(value, buf, sizeof(buf))); | |
// The second field has the actual information | |
neo4j_value_t value2 = neo4j_result_field(result, 1); | |
char buf2[512]; | |
printf("%s\n", neo4j_tostring(value2, buf2, sizeof(buf2))); | |
// Close the Neo4j Connection | |
neo4j_close_results(results); | |
neo4j_close(connection); | |
neo4j_client_cleanup(); | |
return EXIT_SUCCESS; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment