Last active
January 18, 2023 09:05
-
-
Save dev-aritra/ee228fd47c1227666fe14a14e4401134 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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