Fix 2592 neo4j connection options (#2632)

This commit is contained in:
Rickard Cardell 2021-06-11 18:55:30 +02:00 committed by GitHub
parent 5eee818a61
commit 2cb06188ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,20 +27,38 @@ public class Neo4jDriverFactory {
@Value("${NEO4J_MAX_CONNECTION_ACQUISITION_TIMEOUT_IN_SECONDS:60}")
private Long neo4jMaxConnectionAcquisitionTimeout;
@Value("${NEO4j_MAX_CONNECTION_LIFETIME_IN_HOURS:1}")
private Long neo4jMaxConnectionLifetime;
// Kept for sake of backwards compatibility. Instead use NEO4j_MAX_CONNECTION_LIFETIME_IN_SECONDS
@Value("${NEO4j_MAX_CONNECTION_LIFETIME_IN_HOURS:#{null}}")
private Long neo4jMaxConnectionLifetimeInHours;
@Value("${NEO4j_MAX_CONNECTION_LIFETIME_IN_SECONDS:3600}")
private Long neo4jMaxConnectionLifetimeInSeconds;
@Value("${NEO4J_MAX_TRANSACTION_RETRY_TIME_IN_SECONDS:30}")
private Long neo4jMaxTransactionRetryTime;
@Value("${NEO4J_CONNECTION_LIVENESS_CHECK_TIMEOUT_IN_SECONDS:-1}")
private Long neo4jConnectionLivenessCheckTimeout;
@Bean(name = "neo4jDriver")
protected Driver createInstance() {
Config.ConfigBuilder builder = Config.builder();
builder.withMaxConnectionPoolSize(neo4jMaxConnectionPoolSize);
builder.withConnectionAcquisitionTimeout(neo4jMaxConnectionAcquisitionTimeout, TimeUnit.SECONDS);
builder.withMaxConnectionLifetime(neo4jMaxConnectionLifetime, TimeUnit.HOURS);
builder.withMaxConnectionLifetime(neo4jMaxConnectionLifetime(), TimeUnit.SECONDS);
builder.withMaxTransactionRetryTime(neo4jMaxTransactionRetryTime, TimeUnit.SECONDS);
builder.withConnectionLivenessCheckTimeout(neo4jConnectionLivenessCheckTimeout, TimeUnit.SECONDS);
return GraphDatabase.driver(uri, AuthTokens.basic(username, password), builder.build());
}
private Long neo4jMaxConnectionLifetime() {
// neo4jMaxConnectionLifetimeInHours has precedence over neo4jMaxConnectionLifetimeInSeconds
if (neo4jMaxConnectionLifetimeInHours != null) {
return neo4jMaxConnectionLifetimeInHours * 3600;
}
return neo4jMaxConnectionLifetimeInSeconds;
}
}