带有 Vertx 订阅的 Apollo GraphQL 失败
Posted
技术标签:
【中文标题】带有 Vertx 订阅的 Apollo GraphQL 失败【英文标题】:Apollo GraphQL with Vertx Subscription failed 【发布时间】:2020-10-18 06:38:46 【问题描述】:我在暴露于的 docker 实例(窗口机器)上运行 Hasura GraphQL
http://192.168.99.100:8080/v1/graphql
我想在我的 Verticle 中执行订阅,但收到以下异常:
com.apollographql.apollo.exception.ApolloNetworkException: Subscription failed
at com.apollographql.apollo.internal.RealApolloSubscriptionCall$SubscriptionManagerCallback.onNetworkError(RealApolloSubscriptionCall.java:246)
at com.apollographql.apollo.internal.subscription.RealSubscriptionManager$SubscriptionRecord.notifyOnNetworkError(RealSubscriptionManager.java:524)
at com.apollographql.apollo.internal.subscription.RealSubscriptionManager.onTransportFailure(RealSubscriptionManager.java:296)
at com.apollographql.apollo.internal.subscription.RealSubscriptionManager$SubscriptionTransportCallback$2.run(RealSubscriptionManager.java:556)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
这是我的 apollo graphQL 客户端示例代码:
public class MyFirstVerticle extends AbstractVerticle
@Override
public void start(Future<Void> fut)
OkHttpClient okHttp = new OkHttpClient().newBuilder().build();
ApolloClient subscribe = ApolloClient.builder()
.serverUrl("http://192.168.99.100:8080/v1/graphql")
.subscriptionTransportFactory(new WebSocketSubscriptionTransport.Factory(
"wss://192.168.99.100:8080/v1/graphql", okHttp))
.build();
subscribe.subscribe(new MySubscription(1)).execute(new ApolloSubscriptionCall.Callback<Optional<MySubscription.Data>>()
.....
....
【问题讨论】:
【参考方案1】:我找到了解决方案,显然它与您建立的连接类型有关。我不是这方面的专家,但您是否尝试过将 wss 更改为 http?
:-)
【讨论】:
不,我没有尝试将 wss 更改为 HTTP,bcz 我从文档中了解到的是与 graphQL 引擎建立 Web 套接字连接,并且使用了 wss 协议。以上是关于带有 Vertx 订阅的 Apollo GraphQL 失败的主要内容,如果未能解决你的问题,请参考以下文章
使用带有 Kotlin 和流的 Android 上的 Apollo 订阅 GraphQL 时处理网络错误
AWS 云中带有订阅的 Apollo GraphQL 服务器
带有 apollo-angular 客户端的 Aws-appsync 订阅