Redis Consumer Groups is relatively a new feature in Redis and so I couldn't find a matured enough npm package that provide out of the box mechanism to read messages using consumer group. In Spring Data Redis, onMessage(V message)
of StreamListener
interface will be callback on every new message.
I am using redis npm package for Redis and I have to manage message reads by manually firing XREADGROUP command in an infinite loop. Reference.
Though Spring redis library is continuously polling server for new messages and calling onMessage method on new messages but it's taken care by library itself not by the programmer.
From Spring Data Redis
While Pub/Sub relies on the broadcasting of transient messages (i.e. if you don’t listen, you miss a message), Redis Stream use a persistent, append-only data type that retains messages until the stream is trimmed. Another difference in consumption is that Pub/Sub registers a server-side subscription. Redis pushes arriving messages to the client while Redis Streams require active polling.
Code Snippet From Spring Data Redis
private void doLoop(K key) {
do {
try {
// allow interruption
Thread.sleep(0);
List<V> read = readFunction.apply(key, pollState.getCurrentReadOffset());
for (V message : read) {
listener.onMessage(message);
pollState.updateReadOffset(message.getId().getValue());
}
} catch (InterruptedException e) {
cancel();
Thread.currentThread().interrupt();
} catch (RuntimeException e) {
if (cancelSubscriptionOnError.test(e)) {
cancel();
}
errorHandler.handleError(e);
}
} while (pollState.isSubscriptionActive());
}
I was wondering if there is any popular npm package through which I can find a better way to read messages from stream using consumer groups. I am looking something like this redis-streams-broker This package seems unreliable to me as this has fewer downloads, not managed and no License