Neo4j Drivers, version 1.7

A few weeks ago, we released our 1.7 official Neo4j Drivers. For the first time, this covered five languages, namely Java, .Net, Python, JavaScript and Go. Here is what’s in the box.

Photo by Austin Neill on Unsplash
  • Transaction Config
  • Custom Server Address Resolver
  • Server Name Indication (SNI) and hostname verification

Transaction Config

Map<String,Object> metadata = new HashMap<>();
metadata.put( "Username", myUsername );
metadata.put( "Time", ZonedDateTime.now() );
TransactionConfig config = TransactionConfig.builder()
.withMetadata( metadata )
.withTimeout( Duration.ofSeconds( 1 ) )
.build();
try ( Transaction tx = session.beginTransaction( config ) )
{
StatementResult result = tx.run(
"CREATE (a:Greeting) SET a.message = $message " +
"RETURN a.message + ', from node ' + id(a)",
Values.parameters( "message", message ) );
return result.single().get( 0 ).asString();
}
session.run( 
"CREATE (a:Greeting) SET a.message = $message " +
"RETURN a.message + ', from node ' + id(a)",
Values.parameters( "message", message ), config );
session.writeTransaction( tx -> {
StatementResult result = tx.run(
"CREATE (a:Greeting) SET a.message = $message " +
"RETURN a.message + ', from node ' + id(a)",
Values.parameters( "message", message ) );
return result.single().get( 0 ).asString();
}, config );

Custom Server Address Resolver

  • during the very first rediscovery when the driver is created,
  • when all the known routers from the current routing table have failed and the driver needs to fallback to the initial address.
String virtualUri = "bolt+routing://x.acme.com";
Config config = Config.builder()
.withResolver( address -> new HashSet<>( Arrays.asList(
ServerAddress.of( "a.acme.com", 7676 ),
ServerAddress.of( "b.acme.com", 8787 ),
ServerAddress.of( "c.acme.com", 9898 ) ) ) )
.build();
return GraphDatabase.driver( virtualUri, AuthTokens.basic( user, password ), config );

SNI and hostname verification

Config config = Config.builder()
.withEncryption()
.withTrustStrategy(
TrustStrategy.trustCustomCertificateSignedBy(certFile)
.withHostnameVerification() )
.build();
driver = GraphDatabase.driver( uri,
AuthTokens.basic( user, password ), config );

Conclusion

--

--

Developer Content around Graph Databases, Neo4j, Cypher, Data Science, Graph Analytics, GraphQL and more.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store