You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Cosmos DB模拟器连接Gremlin控制台握手失败(200 OK)求助

Azure Cosmos DB模拟器Gremlin连接失败问题

问题描述

执行Gremlin控制台连接命令:remote connect tinkerpop.server conf/remote-localcompute.yaml后,出现连接失败错误,核心错误为:

io.netty.handler.codec.http.websocketx.WebSocketClientHandshakeException: Invalid handshake response getStatus: 200 OK

完整错误日志:

15:42:19.834 [gremlin-driver-host-scheduler-1] ERROR org.apache.tinkerpop.gremlin.driver.Client - Could not initialize client for Host{address=127.0.0.1/127.0.0.1:8081, hostUri=wss://127.0.0.1:8081/gremlin}
15:42:19.853 [main] ERROR org.apache.tinkerpop.gremlin.driver.Client - Initialization failed
java.util.concurrent.CompletionException: Could not initialize 2 (minPoolSize) connections in pool. Successful connections=0. Closing the connection pool.
        at org.apache.tinkerpop.gremlin.driver.ConnectionPool.<init>(ConnectionPool.java:164)
        at org.apache.tinkerpop.gremlin.driver.ConnectionPool.<init>(ConnectionPool.java:103)
        at org.apache.tinkerpop.gremlin.driver.ConnectionPool.<init>(ConnectionPool.java:98)
        at org.apache.tinkerpop.gremlin.driver.Client$ClusteredClient.lambda$new$5(Client.java:584)
        at org.apache.tinkerpop.gremlin.driver.Client$ClusteredClient.lambda$initializeImplementation$0(Client.java:534)
        at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1736)
        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.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
        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:829)
Caused by: org.apache.tinkerpop.gremlin.driver.exception.ConnectionException: Could not open Connection{channel=f290e5d6 host=Host{address=127.0.0.1/127.0.0.1:8081, hostUri=wss://127.0.0.1:8081/gremlin} isDead=false borrowed=0 pending=0 markedReplaced=false closing=false created=2023-03-07T14:42:19.732926600Z thread=gremlin-driver-conn-scheduler-1}
        at org.apache.tinkerpop.gremlin.driver.Connection.<init>(Connection.java:142)
        at org.apache.tinkerpop.gremlin.driver.ConnectionFactory.create(ConnectionFactory.java:34)
        at org.apache.tinkerpop.gremlin.driver.ConnectionPool.lambda$new$0(ConnectionPool.java:130)
        ... 7 common frames omitted
Caused by: org.apache.tinkerpop.gremlin.driver.exception.ConnectionException: Could not complete connection setup to the server. Ensure that SSL is correctly configured at both the client and the server. Ensure that client WebSocket handshake protocol matches the server. Ensure that the server is still reachable.
        at org.apache.tinkerpop.gremlin.driver.Channelizer$WebSocketChannelizer.connected(Channelizer.java:231)
        at org.apache.tinkerpop.gremlin.driver.Connection.<init>(Connection.java:119)
        ... 9 common frames omitted
Caused by: io.netty.handler.codec.http.websocketx.WebSocketClientHandshakeException: Invalid handshake response getStatus: 200 OK
        at io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker13.verify(WebSocketClientHandshaker13.java:312)
        at io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker.finishHandshake(WebSocketClientHandshaker.java:364)
        at io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandshakeHandler.channelRead(WebSocketClientProtocolHandshakeHandler.java:93)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
        at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
        at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:93)
        at io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandler.channelRead(WebSocketClientExtensionHandler.java:125)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
        at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318)
        at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
        at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1373)
        at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1236)
        at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1285)
        at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:529)
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:468)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
        at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        ... 1 common frames omitted
==>Configured 127.0.0.1/127.0.0.1:8081, but host not presently available. The Gremlin Console will attempt to reconnect on each query submission, however, you may wish to close this remote and investigate the problem directly.

已执行的操作步骤:

  • 安装并启动Azure Cosmos DB模拟器,模拟器控制台打开https://localhost:8081/_explorer/index.html
  • 在模拟器资源管理器中创建数据库db1和容器coll1
  • 安装apache-tinkerpop-gremlin-console-3.6.0,在conf目录创建remote-localcompute.yaml,配置内容如下:
hosts: [localhost]
port: 8081
username: /dbs/db1/colls/coll1
password: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
connectionPool: {enableSsl: true}
serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV1d0, config: { serializeResultToString: true }}
  • 启动Gremlin控制台并执行连接命令

解决方案

1. 修正Gremlin端口配置

Azure Cosmos DB模拟器的Gremlin端点端口不是8081,正确端口是8901。修改remote-localcompute.yaml的port字段:

port: 8901

2. 更新序列化器版本

Gremlin Console 3.6.0使用的序列化器版本与Cosmos DB模拟器兼容版本不匹配,替换为GraphSONMessageSerializerV2d0:

serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, config: { serializeResultToString: true }}

3. 信任模拟器的SSL证书

Cosmos DB模拟器使用自签名SSL证书,需将其导入Java信任库,否则会导致SSL连接失败:

  1. 导出模拟器证书:打开https://localhost:8081/_explorer/index.html,点击浏览器地址栏锁图标,导出证书为.cer格式
  2. 导入证书到Java cacerts:
    keytool -importcert -alias cosmosdbemulator -file "path/to/your/certificate.cer" -keystore "path/to/jre/lib/security/cacerts" -storepass changeit
    
    (替换路径为你的Java安装路径和证书文件路径)

4. 验证模拟器Gremlin服务状态

确保模拟器已启动并启用Gremlin API:

  • 打开模拟器控制台,确认"Gremlin"服务状态为"Running"
  • 访问https://localhost:8901验证服务监听状态(浏览器返回400错误为正常,说明服务在运行)

最终正确的remote-localcompute.yaml配置

hosts: [localhost]
port: 8901
username: /dbs/db1/colls/coll1
password: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
connectionPool: {enableSsl: true}
serializer: { className: org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV2d0, config: { serializeResultToString: true }}

完成以上修改后,重新启动Gremlin控制台并执行连接命令即可成功连接。


内容的提问来源于stack exchange,提问作者Peng Liu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 08:52:57