Skip to content

Instantly share code, notes, and snippets.

@razorcd
Created November 22, 2020 22:12
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 razorcd/f0d70570def84ac09750caa6946ce29b to your computer and use it in GitHub Desktop.
Save razorcd/f0d70570def84ac09750caa6946ce29b to your computer and use it in GitHub Desktop.
Scaling reactive APIs - www.razorcodes.com
public class RedisPuller implements AutoCloseable {
private final RedisTemplate<String,String> redisTemplate;
private final Map<String,EventStream> streamsList = new ConcurrentHashMap<>();
private final Thread pullerThread = getPullerThread(this.streamsList);
public RedisPuller(RedisTemplate<String,String> redisTemplate) {
this.redisTemplate = redisTemplate;
this.pullerThread.start();
}
@Override
public void close() {
this.pullerThread.interrupt();
}
private Thread getPullerThread(Map<String,EventStream> streamsList) {
return new Thread(() -> {
while (true) {
try {
staticRedisPoller(streamsList);
} catch (Exception e) {
log.info("Closing RedisPuller#{}: Error: {}", Thread.currentThread(), e);
} finally {
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS); // retry time
}
}
});
}
//... puller methods like above
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment