Created
February 12, 2020 17:28
-
-
Save ganeshs/d25b11535aa0550a169e8ccd0911d108 to your computer and use it in GitHub Desktop.
Bulk handler
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 static class BulkHandler implements Handler, Runnable { | |
private BlockingQueue<Record> queue = new LinkedBlockingQueue<>(1000); | |
public BulkHandler() { | |
new Thread(this).start(); | |
} | |
@Override | |
public Status process(Record record) { | |
queue.offer(record); | |
return Status.SUCCESS; | |
} | |
public void run() { | |
while (true) { | |
if (queue.isEmpty()) { | |
Thread.sleep(100); | |
continue; | |
} | |
List<Record> records = new ArrayList<>(); | |
queue.drainTo(records, 100); | |
process(records); | |
} | |
} | |
public void process(List<Record> records) { | |
try { | |
// Handle bulk records | |
} catch (Exception e) { | |
// Push it to retry or dlq | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment