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

Flush message queue instead of discarding them on shutdown #429

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

koenpunt
Copy link

The default destroyMethod for a Bean is inferred, and uses the close or shutdown method on the object.

But since the shutdown method of the analytics class stops processing of messages, there's a chance that this would discard messages.

By calling flush it should be able to process the messages before shutdown.

Even better might be to implement the blocking flush for the spring boot starter? (https://github.com/segmentio/analytics-java/blob/master/analytics-sample/src/main/java/sample/BlockingFlush.java)

Let me know what you think!

@koenpunt
Copy link
Author

I looked a bit further, and could it be that the shutdown method also performs a final request with the remaining messages?

if (!messages.isEmpty() && (isOverflow || isBlockingSignal || batchSizeLimitReached)) {
Batch batch = Batch.create(CONTEXT, new ArrayList<>(messages), writeKey);
log.print(
VERBOSE,
"Batching %s message(s) into batch %s.",
batch.batch().size(),
batch.sequence());
networkExecutor.submit(
BatchUploadTask.create(AnalyticsClient.this, batch, maximumRetries));

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.

1 participant