Skip to content

Commit ee9a0e5

Browse files
authored
feat(unix): add support for bolt+unix (#1700)
The new `bolt+unix` scheme allows connecting to Neo4j server over a Unix socket. Example: ```java try (var driver = GraphDatabase.driver("bolt+unix:///var/run/neo4j.sock")) { // use the driver var result = driver.executableQuery("SHOW DATABASES") .withConfig(QueryConfig.builder().withDatabase("system").build()) .execute(); result.records().forEach(System.out::println); } ```
1 parent 6132e12 commit ee9a0e5

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

observation/micrometer/src/main/java/org/neo4j/driver/observation/micrometer/DefaultBoltExchangeConvention.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import io.micrometer.common.KeyValue;
2020
import io.micrometer.common.KeyValues;
21+
import java.util.ArrayList;
2122
import java.util.List;
2223

2324
public class DefaultBoltExchangeConvention implements BoltExchangeConvention {
@@ -43,12 +44,17 @@ public String getContextualName(BoltExchangeContext context) {
4344

4445
@Override
4546
public KeyValues getLowCardinalityKeyValues(BoltExchangeContext context) {
46-
return KeyValues.of(
47-
DB_SYSTEM_NAME,
48-
NETWORK_PROTOCOL_NAME,
49-
boltVersion(context),
50-
serverAddress(context),
51-
serverPort(context));
47+
return KeyValues.of(DB_SYSTEM_NAME, NETWORK_PROTOCOL_NAME, boltVersion(context), serverAddress(context))
48+
.and(extraLowCardinalityKeyValues(context));
49+
}
50+
51+
private KeyValues extraLowCardinalityKeyValues(BoltExchangeContext context) {
52+
var list = new ArrayList<KeyValue>();
53+
var serverPort = serverPort(context);
54+
if (serverPort != null) {
55+
list.add(serverPort);
56+
}
57+
return KeyValues.of(list);
5258
}
5359

5460
@Override
@@ -66,8 +72,11 @@ private KeyValue serverAddress(BoltExchangeContext context) {
6672
}
6773

6874
private KeyValue serverPort(BoltExchangeContext context) {
69-
return Neo4jDriverDocumentation.BoltExchangeLowCardinalityKeyNames.SERVER_PORT.withValue(
70-
String.valueOf(context.port()));
75+
var port = context.port();
76+
return port >= 0
77+
? Neo4jDriverDocumentation.BoltExchangeLowCardinalityKeyNames.SERVER_PORT.withValue(
78+
String.valueOf(port))
79+
: null;
7180
}
7281

7382
private KeyValue messages(BoltExchangeContext context) {

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<maven.deploy.skip>true</maven.deploy.skip>
3535

3636
<!-- Versions -->
37-
<neo4j-bolt-connection-bom.version>8.3.0</neo4j-bolt-connection-bom.version>
37+
<neo4j-bolt-connection-bom.version>8.4.0</neo4j-bolt-connection-bom.version>
3838
<reactive-streams.version>1.0.4</reactive-streams.version>
3939
<!-- Please note that when updating this dependency -->
4040
<!-- (i.e. due to a security vulnerability or bug) that the -->

0 commit comments

Comments
 (0)