I frequently encounter the need for creating services that concurrently process messages from Redis queues. So I decided to share the knowledge I learned and help others easily bootstrap such a service. I would like a second opinion from code reviews of the library. Please do contribute if you feel like improving it!
Github repo: https://github.com/ikhoury/rstreamer
Sample usage
You create Worker
classes that processes incoming messages from a queue.
public class SampleWorker implements Worker {
@Override
public void processSingleItem(String item) {
System.out.println("Got item: " + item);
}
}
You link workers to a task queue using a WorkSubscription
:
List<Worker> workers = new ArrayList();
workers.add(new SampleWorker());
WorkSubscription subscription = new WorkSubscription("my:task:queue", workers);
You add your WorkSubscription
to a SubscriptionManager
that handles the lifecycle of all subscriptions.
subscriptionManager.addSubscription(subscription);
subscriptionManager.activateSubscriptions();
Background threads will spin up, continuously poll tasks, and process them using workers.
1 Answer 1
Really good library.
Here are my proposals:
1) Annotation mapping it would be really cool to use annotations (in spring boot application for example) like this:
@RstreamerProcessor
public class SampleWorker {
@RstreamerListener(queue = "my:task:queue")
public void processSingleItem(String item) {
System.out.println("Got item: " + item);
}
}
2) Add the library to maven central(publish artifact) or another repository and describe the usage on README.md
3) Consider to add Spring boot starter spring-boot-custom-starter
4) Add version compatibility table rstreamer to jedis and resilience4j.
5) It would be nice to have exception handling section with samples and description of errors and best practices to handle them.
-
1\$\begingroup\$ Thank you! I will add your ideas to my roadmap. You're welcome to contribute as well. \$\endgroup\$Issa Khoury– Issa Khoury2019年10月01日 15:11:58 +00:00Commented Oct 1, 2019 at 15:11