Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Websocket Reconnection #895

Closed
Syl1234 opened this issue Apr 27, 2018 · 2 comments
Closed

Automatic Websocket Reconnection #895

Syl1234 opened this issue Apr 27, 2018 · 2 comments
Assignees

Comments

@Syl1234
Copy link

Syl1234 commented Apr 27, 2018

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

@sav007
Copy link
Contributor

sav007 commented May 1, 2018

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.

@sav007
Copy link
Contributor

sav007 commented May 1, 2018

Actually I guess we need to add support of heart beat from server side:
https://github.com/apollographql/subscriptions-transport-ws/blob/7482425bb27139d99f45c88ac46c7223c210fbf9/src/message-types.ts#L7

@sav007 sav007 self-assigned this May 1, 2018
sav007 added a commit to sav007/apollo-android that referenced this issue May 23, 2018
Add support of heartbeat messages sent by the subscription server.

Closes apollographql#895
sav007 added a commit to sav007/apollo-android that referenced this issue May 25, 2018
Add support of heartbeat messages sent by the subscription server.

Closes apollographql#895
sav007 added a commit that referenced this issue May 25, 2018
Add support of heartbeat messages sent by the subscription server.

Closes #895
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants