Closed hivenet-mdevarasetty-osi closed 1 year ago
@hivenet-mdevarasetty-osi which mongodb are you using?
@michaelmosmann spring-data-mongodb-3.4.0 & mongodb-driver-4.6.0
@michaelmosmann @transactional rollbacks working good with normal mongodb using AbstractMongoClientConfiguration abstract class.
@hivenet-mdevarasetty-osi is there any public repo where i can have a look?
@hivenet-mdevarasetty-osi .. i worked on this transactional stuff.. please use the latest version and my spring integration ( https://github.com/flapdoodle-oss/de.flapdoodle.embed.mongo.spring/tree/spring-2.7.x)
@michaelmosmann yes i am able to use transactional stuff with latest version in both real time db operations and junits as well.
Below are the configurations made at my side along with the your documentation:
1) Added de.flapdoodle.mongodb.embedded.version=5.0.5 in my local.properties file
2) For TransactionConfig without AbstractMongoClientConfiguration class extension not able to make real time db operation : `@Profile({ "local" }) @Configuration public class EmbededMongoTransactionConfig extends AbstractMongoClientConfiguration {
@Value("${spring.data.mongodb.database}")
private String database;
@Bean
MongoTransactionManager mongoTransactionManager(MongoDatabaseFactory dbFactory) {
return new MongoTransactionManager(dbFactory);
}
@Bean
MongodArguments mongodArguments() {
return MongodArguments.builder().replication(Storage.of(database, 10)).build();
}
@Override
protected String getDatabaseName() {
return database;
}
} `
3) At Junits: added below annotation to the class
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@michaelmosmann while running getting below info log, anyhow its not stopping the flow but looking odd in logs.
2022-12-19 15:00:08.468 [INFO ] [main] client - MongoClient with metadata {"driver": {"name": "mongo-java-driver|sync|spring-data", "version": "4.6.0"}, "os": {"type": "Darwin", "name": "Mac OS X", "architecture": "x86_64", "version": "13.1"}, "platform": "Java/Oracle Corporation/18.0.1.1+2-6"} created with settings MongoClientSettings{readPreference=primary, writeConcern=WriteConcern{w=null, wTimeout=null ms, journal=null}, retryWrites=true, retryReads=true, readConcern=ReadConcern{level=null}, credential=null, streamFactoryFactory=null, commandListeners=[], codecRegistry=ProvidersCodecRegistry{codecProviders=[ValueCodecProvider{}, BsonValueCodecProvider{}, DBRefCodecProvider{}, DBObjectCodecProvider{}, DocumentCodecProvider{}, IterableCodecProvider{}, MapCodecProvider{}, GeoJsonCodecProvider{}, GridFSFileCodecProvider{}, Jsr310CodecProvider{}, JsonObjectCodecProvider{}, BsonCodecProvider{}, EnumCodecProvider{}, com.mongodb.Jep395RecordCodecProvider@538b3c88]}, clusterSettings={hosts=[127.0.0.1:27017], srvServiceName=mongodb, mode=SINGLE, requiredClusterType=UNKNOWN, requiredReplicaSetName='null', serverSelector='null', clusterListeners='[]', serverSelectionTimeout='30000 ms', localThreshold='30000 ms'}, socketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=0, receiveBufferSize=0, sendBufferSize=0}, heartbeatSocketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=10000, receiveBufferSize=0, sendBufferSize=0}, connectionPoolSettings=ConnectionPoolSettings{maxSize=100, minSize=0, maxWaitTimeMS=120000, maxConnectionLifeTimeMS=0, maxConnectionIdleTimeMS=0, maintenanceInitialDelayMS=0, maintenanceFrequencyMS=60000, connectionPoolListeners=[], maxConnecting=2}, serverSettings=ServerSettings{heartbeatFrequencyMS=10000, minHeartbeatFrequencyMS=500, serverListeners='[]', serverMonitorListeners='[]'}, sslSettings=SslSettings{enabled=false, invalidHostNameAllowed=false, context=null}, applicationName='null', compressorList=[], uuidRepresentation=JAVA_LEGACY, serverApi=null, autoEncryptionSettings=null, contextProvider=null} 2022-12-19 15:00:08.474 [INFO ] [cluster-ClusterId{value='63a02f20b0fa5d5f649e1977', description='null'}-127.0.0.1:27017] cluster - Exception in monitor thread while connecting to server 127.0.0.1:27017 com.mongodb.MongoSocketOpenException: Exception opening socket at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) ~[mongodb-driver-core-4.6.0.jar:?] at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:180) ~[mongodb-driver-core-4.6.0.jar:?] at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:193) ~[mongodb-driver-core-4.6.0.jar:?] at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:157) ~[mongodb-driver-core-4.6.0.jar:?] at java.lang.Thread.run(Thread.java:833) ~[?:?] Caused by: java.net.ConnectException: Connection refused at sun.nio.ch.Net.pollConnect(Native Method) ~[?:?] at sun.nio.ch.Net.pollConnectNow(Net.java:672) ~[?:?] at sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:539) ~[?:?] at sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:594) ~[?:?] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327) ~[?:?] at java.net.Socket.connect(Socket.java:633) ~[?:?] at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:107) ~[mongodb-driver-core-4.6.0.jar:?] at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79) ~[mongodb-driver-core-4.6.0.jar:?] at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ~[mongodb-driver-core-4.6.0.jar:?]
@hivenet-mdevarasetty-osi so now it works (which i hope)?
@hivenet-mdevarasetty-osi that he tries to connect to the default port makes me wonder..
@michaelmosmann yes its working for now, but will confirm you once fully integrated and tested.
@hivenet-mdevarasetty-osi that he tries to connect to the default port makes me wonder..
@michaelmosmann i configured spring.data.mongodb.port=27017 in my properties because i wanted to access local embedded mongo db through compass tool instead of random port.
Even i change it to some other port like 1234, still getting same weird log.
@hivenet-mdevarasetty-osi .. is there any root cause? can you tell when this happens (before each test, after each test, ...)?
@michaelmosmann getting MongoSocketOpenException as a INFO log during application startup. (only one time)
@hivenet-mdevarasetty-osi i will have a look at my test if there is also such exception..
@hivenet-mdevarasetty-osi is this still an issue?
@michaelmosmann we haven't fully integrated this feature, as of now no issues..
@hivenet-mdevarasetty-osi ok.. if any questions, just ask:)
@hivenet-mdevarasetty-osi i close this issue.. just reopen, if needed:)
@michaelmosmann in my project i am running using embedded mongodb in local machines, wanted to have a support of @transactional rollback operations in my apis. Could you please refer me if any documents to integrate embedded mongodb with transacational.
Current functionality: Now even i add @transactional to my apis, rollback functionality is not working.
Springboot 2.7.0 JDK 18 embed.mongo 3.5.0