Ошибка «имя SNI не отправлено» при подключении к Atlas MongoDB с использованием драйвера реактивных потоков java - PullRequest
0 голосов
/ 19 марта 2020

Я пытаюсь подключиться к моей базе данных Atlas MongoDB, используя драйвер реактивного потока mongodb для java. Когда я пытаюсь сделать это с этим кодом, я получаю сообщение об ошибке «имя SNI не отправлено, обязательно используйте драйвер / оболочку MongoDB 3.4+». Я использую драйвер MongoDB 3.12.2 java, реактивные потоки 1.13.1, java 11 и 4.2.3 MongoDB через Atlas.

        MongoClient databaseClient = MongoClients.create("mongodb+srv://<database>:<password>@vestia-shyqn.gcp.mongodb.net/test?retryWrites=true&w=majority&ssl=true");
        MongoDatabase database = databaseClient.getDatabase("development");
        MongoCollection<Document> collection = database.getCollection("testing");
        Document doc = new Document("testing", "123");
        collection.insertOne(doc).subscribe(new Subscriber<Success>() {
            @Override
            public void onSubscribe(Subscription s) {
                s.request(1);
            }

            @Override
            public void onNext(Success success) {
                System.out.println("Called: onNext");
            }

            @Override
            public void onError(Throwable t) {
                System.out.println("Called: onError");
                t.printStackTrace();
            }

            @Override
            public void onComplete() {
                System.out.println("Called: onComplete");
            }
        });

Stacktrace:

Mar 19, 2020 4:42:20 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Cluster created with settings {hosts=[127.0.0.1:27017], srvHost=vestia-shyqn.gcp.mongodb.net, mode=MULTIPLE, requiredClusterType=REPLICA_SET, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500, requiredReplicaSetName='Vestia-shard-0'}
Mar 19, 2020 4:42:20 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: No server chosen by com.mongodb.async.client.ClientSessionHelper$1@895e367 from cluster description ClusterDescription{type=UNKNOWN, connectionMode=MULTIPLE, serverDescriptions=[]}. Waiting for 30000 ms before timing out
Mar 19, 2020 4:42:20 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Adding discovered server vestia-shard-00-02-shyqn.gcp.mongodb.net:27017 to client view of cluster
Mar 19, 2020 4:42:20 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Adding discovered server vestia-shard-00-01-shyqn.gcp.mongodb.net:27017 to client view of cluster
Mar 19, 2020 4:42:20 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Adding discovered server vestia-shard-00-00-shyqn.gcp.mongodb.net:27017 to client view of cluster
Mar 19, 2020 4:42:21 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:2, serverValue:293661}] to vestia-shard-00-01-shyqn.gcp.mongodb.net:27017
Mar 19, 2020 4:42:21 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:3, serverValue:300643}] to vestia-shard-00-00-shyqn.gcp.mongodb.net:27017
Mar 19, 2020 4:42:21 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Monitor thread successfully connected to server with description ServerDescription{address=vestia-shard-00-01-shyqn.gcp.mongodb.net:27017, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 3]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=38130500, setName='Vestia-shard-0', canonicalAddress=vestia-shard-00-01-shyqn.gcp.mongodb.net:27017, hosts=[vestia-shard-00-00-shyqn.gcp.mongodb.net:27017, vestia-shard-00-02-shyqn.gcp.mongodb.net:27017, vestia-shard-00-01-shyqn.gcp.mongodb.net:27017], passives=[], arbiters=[], primary='vestia-shard-00-01-shyqn.gcp.mongodb.net:27017', tagSet=TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='GCP'}, Tag{name='region', value='CENTRAL_US'}]}, electionId=7fffffff0000000000000004, setVersion=1, lastWriteDate=Thu Mar 19 16:42:21 EDT 2020, lastUpdateTimeNanos=485738294061100}
Mar 19, 2020 4:42:21 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Opened connection [connectionId{localValue:1, serverValue:282746}] to vestia-shard-00-02-shyqn.gcp.mongodb.net:27017
Mar 19, 2020 4:42:21 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Setting max election id to 7fffffff0000000000000004 from replica set primary vestia-shard-00-01-shyqn.gcp.mongodb.net:27017
Mar 19, 2020 4:42:21 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Setting max set version to 1 from replica set primary vestia-shard-00-01-shyqn.gcp.mongodb.net:27017
Mar 19, 2020 4:42:21 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Discovered replica set primary vestia-shard-00-01-shyqn.gcp.mongodb.net:27017
Mar 19, 2020 4:42:21 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Monitor thread successfully connected to server with description ServerDescription{address=vestia-shard-00-00-shyqn.gcp.mongodb.net:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 3]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=36108600, setName='Vestia-shard-0', canonicalAddress=vestia-shard-00-00-shyqn.gcp.mongodb.net:27017, hosts=[vestia-shard-00-00-shyqn.gcp.mongodb.net:27017, vestia-shard-00-02-shyqn.gcp.mongodb.net:27017, vestia-shard-00-01-shyqn.gcp.mongodb.net:27017], passives=[], arbiters=[], primary='vestia-shard-00-01-shyqn.gcp.mongodb.net:27017', tagSet=TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='GCP'}, Tag{name='region', value='CENTRAL_US'}]}, electionId=null, setVersion=1, lastWriteDate=Thu Mar 19 16:42:21 EDT 2020, lastUpdateTimeNanos=485738318602400}
Mar 19, 2020 4:42:21 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Monitor thread successfully connected to server with description ServerDescription{address=vestia-shard-00-02-shyqn.gcp.mongodb.net:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[4, 2, 3]}, minWireVersion=0, maxWireVersion=8, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=37406400, setName='Vestia-shard-0', canonicalAddress=vestia-shard-00-02-shyqn.gcp.mongodb.net:27017, hosts=[vestia-shard-00-00-shyqn.gcp.mongodb.net:27017, vestia-shard-00-02-shyqn.gcp.mongodb.net:27017, vestia-shard-00-01-shyqn.gcp.mongodb.net:27017], passives=[], arbiters=[], primary='vestia-shard-00-01-shyqn.gcp.mongodb.net:27017', tagSet=TagSet{[Tag{name='nodeType', value='ELECTABLE'}, Tag{name='provider', value='GCP'}, Tag{name='region', value='CENTRAL_US'}]}, electionId=null, setVersion=1, lastWriteDate=Thu Mar 19 16:42:21 EDT 2020, lastUpdateTimeNanos=485738335063300}
Called: onError
com.mongodb.MongoCommandException: Command failed with error 8000 (AtlasError): 'no SNI name sent, make sure using a MongoDB 3.4+ driver/shell.' on server vestia-shard-00-01-shyqn.gcp.mongodb.net:27017. The full response is {"ok": 0, "errmsg": "no SNI name sent, make sure using a MongoDB 3.4+ driver/shell.", "code": 8000, "codeName": "AtlasError"}
    at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:175)
    at com.mongodb.internal.connection.InternalStreamConnection$2$1.onResult(InternalStreamConnection.java:390)
    at com.mongodb.internal.connection.InternalStreamConnection$2$1.onResult(InternalStreamConnection.java:376)
    at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:677)
    at com.mongodb.internal.connection.InternalStreamConnection$MessageHeaderCallback$MessageCallback.onResult(InternalStreamConnection.java:644)
    at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:514)
    at com.mongodb.internal.connection.InternalStreamConnection$5.completed(InternalStreamConnection.java:511)
    at com.mongodb.internal.connection.AsynchronousChannelStream$BasicCompletionHandler.completed(AsynchronousChannelStream.java:220)
    at com.mongodb.internal.connection.AsynchronousChannelStream$BasicCompletionHandler.completed(AsynchronousChannelStream.java:203)
    at com.mongodb.internal.connection.tlschannel.async.AsynchronousTlsChannel$3$1.run(AsynchronousTlsChannel.java:151)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834)
Mar 19, 2020 4:42:22 PM com.mongodb.diagnostics.logging.JULLogger log
INFO: Closed connection [connectionId{localValue:4}] to vestia-shard-00-01-shyqn.gcp.mongodb.net:27017 because there was a socket exception raised by this connection.

Кажется, я понял, как подключиться к базе данных, добавив «& ssl = true» в конец строки подключения, но я все еще получаю сообщение об ошибке при попытке записи.

pom. xml:

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.target>11</maven.compiler.target>
        <maven.compiler.source>11</maven.compiler.source>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongodb-driver-reactivestreams</artifactId>
            <version>1.13.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <version>3.7.0</version>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
...