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

fix: topics subscription resiliency #38

Merged
merged 4 commits into from
Dec 27, 2023
Merged

fix: topics subscription resiliency #38

merged 4 commits into from
Dec 27, 2023

Conversation

anitarua
Copy link
Collaborator

@anitarua anitarua commented Dec 22, 2023

addresses #27

if subscription was not cancelled explicitly using the unsubscribe method on the TopicSubscription class, the topic client will attempt to re-establish a connection.

adds a grpc manager class for the topic client so we can easily extend the internal topic client to use multiple grpc connections in the future if needed.

manually tested and confirmed that:

  • only one TCP connection is opened when the topics example is running
  • unsubscribe will cancel the subscription and still allow the topic client to subscribe to a topic afterwards
  • topic client will reconnect after wifi is turned off for 1min
  • topic client will reconnect after wifi is turned off for 5min (though the default backoff strategy seems to make it wait so it takes about 1min before it actually reconnects after the wifi is restored)

@anitarua anitarua marked this pull request as ready for review December 27, 2023 19:03
}
case TopicSubscribeError():
print("Subscribe error: ${sub.errorCode} ${sub.message}");
}

// unsubscribing should not affect the topic client's ability

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really useful, I imagine it was great as almost a TDD approach to working on this feature. In the long run though, we probably want to keep these examples as simple as humanly possible, so we might want to move this to an "advanced topics example" or something.

Not in any way, shape, or form a blocker for this PR :) just calling it out as something to be aware of for future touching up on these examples/docs and stuff.

@@ -30,6 +70,10 @@ class TopicSubscription implements TopicSubscribeResponse {
}
return null;
}

void unsubscribe() async {
await _stream.cancel();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link

@cprice404 cprice404 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this lgtm! I didn't pull it down and test it or anything, we should definitely have a second person test it next week, but definitely looks good to merge for now!

@@ -21,7 +23,7 @@ class TopicClient implements ITopicClient {
TopicClient(
CredentialProvider credentialProvider, TopicConfiguration configuration)
: _pubsubClient = ClientPubsub(credentialProvider, configuration) {
_logger.level = determineLoggerLevel(configuration.logLevel);
// _logger.level = determineLoggerLevel(configuration.logLevel);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errant comments, maybe remove in a later PR.


@override
void close() {
_pubsubClient.close();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:thu

@anitarua
Copy link
Collaborator Author

cc @bruuuuuuuce merging it now but we should loop back and test it more thoroughly

@anitarua anitarua merged commit c88060c into main Dec 27, 2023
1 check passed
@anitarua anitarua deleted the topic-resiliency branch December 27, 2023 20:55
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

Successfully merging this pull request may close these issues.

2 participants