Spring 引导应用程序中使用 DB2 Wirelistener (NoSQL) 的异常

Exception using DB2 Wirelistener (NoSQL) from a Spring Boot application

我已将 DB2 设置为 NoSQL 存储(遵循 https://www.ibm.com/developerworks/data/library/techarticle/dm-1306nosqlforjson4/index.html)。 IBM 的前提是,如果我们在两者之间添加 Wire Listener,任何与 MongoDB 通信的应用程序都可以切换到 DB2。

布局为:客户端应用程序----> Wire listener ----> DB2

使用以下命令启动 Wire 侦听器:

wlpListener -start -mongoPort 27017 -userid <user> -password <password> -dbName jsondb -logPath c:/temp/logs -host 10.0.0.6:50000

该解决方案适用于简单的 Python 客户端:

from pymongo import MongoClient
client = MongoClient('10.0.0.6', 27017)
database = client['jsondb']
coll = database.mycollection
coll.insert_one({"name":"Jerry","age":5})
print(coll.find_one({"name": "Jerry"}))

但是,当我使用为 MongoDB 设计的 Spring 引导应用程序(使用 Spring Data JPA)时,我在初始化期间遇到以下异常:

  .   ____          _            __ _ _
 /\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.2)

2021-02-14 11:13:28.629  INFO 11820 --- [           main] c.i.a.n.generator.gen.MainGenerator      : Starting MainGenerator using Java 1.8.0 on SP-NIT09160021 with PID 11820 (C:\Users\user\Documents\Workspaces\nosql-poc-db2-wirednosql\target\classes started by user in C:\Users\user\Documents\Workspaces\nosql-poc-db2-wirednosql)
2021-02-14 11:13:28.635  INFO 11820 --- [           main] c.i.a.n.generator.gen.MainGenerator      : No active profile set, falling back to default profiles: default
2021-02-14 11:13:29.375  INFO 11820 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2021-02-14 11:13:29.450  INFO 11820 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 69 ms. Found 3 MongoDB repository interfaces.
2021-02-14 11:13:30.006  INFO 11820 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-02-14 11:13:30.016  INFO 11820 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-02-14 11:13:30.016  INFO 11820 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-02-14 11:13:30.132  INFO 11820 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-02-14 11:13:30.132  INFO 11820 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1414 ms
2021-02-14 11:13:30.304  INFO 11820 --- [           main] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[10.0.0.6:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms'}
2021-02-14 11:13:30.380  INFO 11820 --- [-10.0.0.6:27017] org.mongodb.driver.cluster               : Exception in monitor thread while connecting to server 10.0.0.6:27017
com.mongodb.MongoException: org.bson.BsonInvalidOperationException: Value expected to be of type INT32 is of unexpected type DOUBLE
             at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:157) ~[mongodb-driver-core-4.1.1.jar:na]
             at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:188) ~[mongodb-driver-core-4.1.1.jar:na]
             at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:144) ~[mongodb-driver-core-4.1.1.jar:na]
             at java.lang.Thread.run(Thread.java:785) [na:1.8.0-internal]
Caused by: org.bson.BsonInvalidOperationException: Value expected to be of type INT32 is of unexpected type DOUBLE
             at org.bson.BsonValue.throwIfInvalidType(BsonValue.java:419) ~[bson-4.1.1.jar:na]
             at org.bson.BsonValue.asInt32(BsonValue.java:94) ~[bson-4.1.1.jar:na]
             at org.bson.BsonDocument.getInt32(BsonDocument.java:555) ~[bson-4.1.1.jar:na]
             at com.mongodb.internal.connection.DescriptionHelper.getMaxWireVersion(DescriptionHelper.java:104) ~[mongodb-driver-core-4.1.1.jar:na]
             at com.mongodb.internal.connection.DescriptionHelper.createConnectionDescription(DescriptionHelper.java:63) ~[mongodb-driver-core-4.1.1.jar:na]
             at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:117) ~[mongodb-driver-core-4.1.1.jar:na]
             at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:62) ~[mongodb-driver-core-4.1.1.jar:na]
             at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:144) ~[mongodb-driver-core-4.1.1.jar:na]
             ... 3 common frames omitted

好像 Mongo 驱动程序与 Wire Listener 所期望的不兼容。

版本:

这是 Wire Listener 中的错误。

MongoDB 驱动程序需要一个 Int:

    private static int getMinWireVersion(final BsonDocument isMasterResult) {
        return isMasterResult.getInt32("minWireVersion", new BsonInt32(getDefaultMinWireVersion())).getValue();
    }

    private static int getMaxWireVersion(final BsonDocument isMasterResult) {
        return isMasterResult.getInt32("maxWireVersion", new BsonInt32(getDefaultMaxWireVersion())).getValue();
    }

但是 Wire Listener 正在报告 Double。

我建议从 IBM 支持获取最新的 IBM DB2 NoSQL WireListener,其中包含此问题的修复程序。 如果您从 github 下载 quick fix 没有问题,您可以下载并使用此文件:https://github.com/ibmdb/db2drivers/blob/main/db2NoSQLWireListener1.4.119.zip 它包含此问题的修复程序。谢谢