Add non-reactive message retrieval functions
I know, this library is called reactive messaging. Indeed, I have many reactive messaging use cases in my application and really like to use this library in that context. However, I also have the need to be able to pull a message from the queue when I want to. Currently I don't see how this would be possible with smallrye-reactive-messaging and I don't like that I have to use another messaging library just because of that.
In this use case, I utilize my queue as a task (trigger) queue. My application is only allowed to run a certain number of tasks in parallel. These tasks run on another system and my application only triggers them and observes the running task untill it is either finished or failed and reports back that status.
With only reactive APIs, I see no possibility to pull a new task from the queue, when the task pool is already filled and an old one just finished. Or am I missing an API?
I think the idea of beeing able to pull from a queue (the most basic way of using a queue) should also be implemented in such a library, since there sometimes just are non-reactive use cases mixed in with the reactive use cases.
It's definitely something we'd be interested in.
In terms of how it could work, maybe a new interface called Pollable that the connectors implement so a user can do:
@Inject
@Channel("...")
Pollable<Message<String>> source;
The user receives the Message and would need to manually handle the acknowledgment of it.
If a particular connector implementation didn't support requesting a single message directly, then the deployment process should fail is that connector is present in the application.
The implementation would connect and do request(1), and then source.poll() and get a CompletionStage<Message>, or it would be source.pollAndAwait() for a blocking version.
If you'd be interested in putting a pull request together for this that would be awesome, and we'd help with questions along the way.
I'm not sure, if I find the time at the moment. However, I will keep it on my list. If somebody else wants to do it in the meantime, it's obviously fine as well ;).
Closing this as this is easily achievable now with the Mutiny API: https://smallrye.io/smallrye-mutiny/2.5.1/guides/reactive-to-imperative/#iterating-over-multis-items
One can inject a channel as Multi and subscribe to it with a blocking iterator:
@Inject
@Channel("data")
Multi<String> channel;
private Iterator<String> iterator;
public void start() {
iterator = channel.subscribe().asIterable().iterator();
}
public String get() {
return iterator.next();
}
The queue used for the iterator can also be configured.