Introducing Neo4j drivers for the next gen database
The latest Neo4j 4.0 drivers are here! The new drivers have been designed to work together with Neo4j 4.0, Neo4j’s Database-as-a Service solution Aura, and Neo4j’s federation framework Fabric. The 4.0 drivers are built to provide a user-friendly and unified API across all languages to take advantage of these new features and services.
What’s in a name?
To better align with Neo4j versions, the decision was made to release the driver as 4.0.0 rather than 2.0.0 (which would have followed the previous convention, and would have been the next version up from 1.7).
The following languages have drivers available as version 4.0:
- Java
- .NET
- JavaScript
4.0 drivers for Python and Go will be available soon.
The current stable 1.7 driver release for these languages will work in fallback mode with Neo4j 4.0, which means that all functionality that is available in Neo4j 3.5 will continue to work. However, new functionality introduced in Neo4j 4.0 will not exist.
New features
The biggest driving feature for the latest version of the drivers is support for Neo4j 4.0
- Bolt 4.0 is implemented for drivers and Neo4j 4.0
- Reactive streams is now available, including client side back-pressure support
- The new feature detection method
driver.supportsMultiDb()
for 4.0, and connectivity checking methoddriver.verifyConnectivity()
method Session
need to be acquired against a specific database. This is due to the multi-database feature now available in Neo4j 4.0
You can use the new drivers with 3.5 series of the Neo4j database. Do be aware you won’t be able to use the new features such as multi-database, back pressure, and reactive sessions, you’ll need Neo4j 4.0 for that!
Breaking changes
As with all major releases, there can be breaking changes, and with the latest version of the Neo4j drivers, the following changes have been made:
- Default configuration for encrypted is false. if you enable encryption, the default trust mode is determined by operating system (e.g. self-signed certificates will fail on certificate validation by default)
- Hostname verification is turned on by default when encryption is turned on
- v1 is removed from the driver’s package name. You only need the package name of org.neo4j.driver, rather than org.neo4j.driver.v1
- You no longer need to use the protocol bolt:// or bolt+routing:// in connection strings when working with clustered deployments. This is replaced by neo4j://. You can still use bolt:// for a single-instance, or with a single member in a cluster
- For the Java and .NET drivers, asynchronous methods have been extracted out and put in
AsynchSession
, whereas synchronous methods remain inSession
. This change ensures that blocking and non-blocking APIs don’t accidentally get mixed. - For synchronous
Transaction
API,Transaction#success
andTransaction#failure
have been replaced withTransaction#commit
andTransaction#rollback
. A transaction in Neo4j 4.0 can only be committed or rolled back once. If a transaction is not committed explicitly usingTransaction#commit
,Transaction#close
will roll back the transaction. - There has also been some name simplification for clarity;
Statement
has been renamed toQuery
;StatementResult
has been changed toResult
;StatementResultCursor
has been changed toResultCursor
. Driver#session
method now uses a session configuration object or option building rather than method arguments- Bookmark has changed from a
String
or aList<String>
to aBookmark
object - A result can only be consumed once. This occurs either if the query result has been discarded by invoking
Result#consume
and/or the outer scope where the result is created, such as the transaction or session, has been closed LoadBalancingStrategy
is removed fromConfig
class and the drivers always default toLeastConnectedStrategy
.
Racing to the resources
You can get the latest driver documentation from here, including example code snippets.