Skip to content

Instantly share code, notes, and snippets.

@dev-aritra
Last active January 18, 2023 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dev-aritra/ee228fd47c1227666fe14a14e4401134 to your computer and use it in GitHub Desktop.
Save dev-aritra/ee228fd47c1227666fe14a14e4401134 to your computer and use it in GitHub Desktop.
public void consume(Message<String> message) {
try {
final EventHandler handler = subscriptionMap.get(event); // Selecting a appropriate handler based on the message
processWithRetry(handler, message);
} catch (RequeableException e) {
failureHandler.reQueue(message, e);
} catch (DroppableException e) {
failureHandler.dropMessage(message, e);
} catch (Exception e) {
failureHandler.putOnDlq(message, e);
}
}
private void processWithRetry(EventHandler handler, Message<String> message)
throws Exception {
retryTemplate.execute(context -> {
handler.handle(message); // Processing delegated to the handler method
return null;
}, context -> {
final Exception originalError = (Exception) context.getLastThrowable();
if (originalError instanceof RetryableException) {
throw new RequeableException(originalError); // After cutoff RetryableException exception becomes RequeableException
}
throw originalError;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment