analytics-java icon indicating copy to clipboard operation
analytics-java copied to clipboard

Flush message queue instead of discarding them on shutdown

Open koenpunt opened this issue 2 years ago • 1 comments

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 avatar Apr 19 '23 09:04 koenpunt

I looked a bit further, and could it be that the shutdown method also performs a final request with the remaining messages? https://github.com/segmentio/analytics-java/blob/9e9492faa71486a7c4a133422d6ca57ded3f8093/analytics/src/main/java/com/segment/analytics/internal/AnalyticsClient.java#L306-L314

koenpunt avatar Apr 19 '23 09:04 koenpunt