Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I have 2 springboot service. 1 springboot service is connected to localhost:27107 Mongodb. Another springboot service is connected to 172.
.*
.***:27018 (Hosted somewhere). Both codes are the same except for the MongoClient connection values.
This is the code below.
MongoClient mongoClient;
MongoDatabase database;
public FeedStorage() {
mongoClient = MongoClients.create(FeedConfig.MONGODB_HOST);
database = mongoClient.getDatabase(FeedConfig.DATABASE_NAME);
For the 2nd springboot service, I am getting error
Caused by: com.mongodb.MongoSocketReadException: Exception receiving message
at com.mongodb.internal.connection.InternalStreamConnection.translateReadException(InternalStreamConnection.java:543)
at com.mongodb.internal.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:428)
But the 1st one is okay. I am not sure why this is happening. Is localhost and hosted connection different?
When the connection between the mongodb server and the client fails (such as a sudden interruption of the network link), the client does not actively reclaim these connections by default, and the above error occurs when the connection is read and written again.
you can set the maxConnectionIdleTime
in MongoClientOption
when create mongoClient
@Configuration
public class MongoDbSettings {
@Bean
public MongoClientOptions mongoOptions() {
return MongoClientOptions
.builder()
.maxConnectionIdleTime(60000)
.build();
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.