Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* Logging improvement and extension options for DaemonMessageListener
* Add TLS server parameters for JAX-RS
* Improved Errormessage in case of non parseable JSON strings in the space of InterconnectObjects and Messsaging.
* Add connection pool settings and idle timeout to MongoDB client configuration


# 1.37
Expand Down
3 changes: 3 additions & 0 deletions mongodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ For connections to real MongoDB databases, these extra properties can be set:
* `mongodb.uri` - instead of host and port you can specify the complete connection string
* `mongodb.sockettimeout` - the socket timeout of the connection (default: 10 seconds)
* `mongodb.connecttimeout` - the connection timeout of the connection attempt (default: 10 seconds)
* `mongodb.maxConnectionIdleTime` - the maximum idle time for pooled connections in milliseconds (default: 600000 / 10 minutes)
* `mongodb.minPoolSize` - the minimum number of connections in the connection pool (default: 10)
* `mongodb.maxPoolSize` - the maximum number of connections in the connection pool (default: 100)

### Access to database

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.mongodb.MongoClientSettings.Builder;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import de.taimos.daemon.DaemonStarter;
import de.taimos.daemon.spring.conditional.OnSystemProperty;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand All @@ -51,17 +52,33 @@ public class RealClientConfig {
@Value("${mongodb.connecttimeout:${mongodb.connectTimeout:10000}}")
private int connectTimeout;

@Value("${mongodb.maxConnectionIdleTime:600000}")
private int maxConnectionIdleTime = 600000;

@Value("${mongodb.minPoolSize:10}")
private int minPoolSize = 10;

@Value("${mongodb.maxPoolSize:100}")
private int maxPoolSize = 100;

/**
* @return the configured mongo client
*/
@Bean
public MongoClient mongoClient() {
Builder settingsBuilder = MongoClientSettings.builder();
settingsBuilder.applyConnectionString(new ConnectionString(this.mongoURI));
settingsBuilder.applicationName(DaemonStarter.getDaemonName());
settingsBuilder.applyToSocketSettings(builder -> {
builder.connectTimeout(RealClientConfig.this.connectTimeout, TimeUnit.MILLISECONDS);
builder.readTimeout(RealClientConfig.this.socketTimeout, TimeUnit.MILLISECONDS);
});

settingsBuilder.applyToConnectionPoolSettings(builder -> {
builder.minSize(this.minPoolSize);
builder.maxSize(this.maxPoolSize);
builder.maxConnectionIdleTime(RealClientConfig.this.maxConnectionIdleTime, TimeUnit.MILLISECONDS);
});
return MongoClients.create(settingsBuilder.build());
}

Expand Down