Created
November 22, 2020 22:12
-
-
Save razorcd/f0d70570def84ac09750caa6946ce29b to your computer and use it in GitHub Desktop.
Scaling reactive APIs - www.razorcodes.com
This file contains hidden or 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 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