Add "Max Attempts" limit

Currently the client keep sending the events to the server if they have failed (because they never being removed from the queue), which cause the timeout function to run every X seconds, for infinite times.

maxAttempts is a configurable limit that clears the timeout function once the number of failed attempts (in a row) exceeds it.