Apollo-android: Automatic Websocket Reconnection

Created on 27 Apr 2018  路  2Comments  路  Source: apollographql/apollo-android

I sucessfully managed to use ApolloClient in order to deal with GraphQL Subscription over websocket. I can see events onNext happening. Unfortunatly when my server is facing difficulties, ApolloClient is not able to reconnect using the same websocket.

`

 private ApolloSubscriptionCall<Subscription.Data> getMySubscriptionCall() {
    Subscription = Subscription.builder().build();
    return apolloClient.subscribe(Subscription);
}

/* */

    okHttpClient = new OkHttpClient.Builder()
            .addInterceptor(new LoggingInterceptor())
            .pingInterval(30, TimeUnit.SECONDS)
            .retryOnConnectionFailure(true)
            .build();

    apolloClient = ApolloClient.builder()
            .serverUrl(env.getBaseUrl())
            .okHttpClient(okHttpClient)
            .subscriptionTransportFactory(new WebSocketSubscriptionTransport.Factory(env.getSubscriptionBaseUrl(), okHttpClient))
            .build();

    disposables.add(Rx2Apollo.from(getMySubscriptionCall())
            .subscribeOn(Schedulers.io())
            .subscribeWith(new Subscriber()));

`

Is there any other particular configuration that i must add in order to reconnect the client ?

Thx for advices

Enhancement

Most helpful comment

All 2 comments

Have you tried to unsubscribe and then subscribe after some delay like 10-20 seconds? After 10 sec timeout we will kill web socket connection.

Was this page helpful?
0 / 5 - 0 ratings