How to populate a Multi from the contents of an actively changing Queue? #1562
Replies: 3 comments
-
Follow-up: I think I'm a lot closer. For now I've tried this:
My logic is that it appears Or, maybe I replace the
Apologies for the kind of slow stream-of-consciousness as I work through this problem. I didn't see a discussion of someone going through this, and I'm hoping my experience and any other feedback that's provided will prove helpful to someone else in the future. |
Beta Was this translation helpful? Give feedback.
-
Alright, so this still isn't working, and I don't know why. Here's my current code:
Here's the problem. I never see that |
Beta Was this translation helpful? Give feedback.
-
Hi. I suppose you could use reactive messaging here? It would probably simplify the problem. On the component that does the expensive operation, you inject an Then: @GET
@Path("/queueRead")
@RestStreamElementType(MediaType.APPLICATION_JSON)
public Multi<float[]> queueRead() {
return resultsStream;
} A problem arises in the mismatch of the imperative producer and the async consumption. Ie: the producer keeps producing when maybe no one is reading yet. You solve that with an overflow strategy. Take a look at https://smallrye.io/smallrye-reactive-messaging/4.3.0/concepts/emitter/#overflow-management If the messaging paradigm is too much, you can have a service (lets call it QueueService) acting as a connector between the producer (the one filling the queue) and the consumers (the controller) and use this strategy: https://smallrye.io/smallrye-mutiny/latest/guides/integrate-a-non-reactive-source/ |
Beta Was this translation helpful? Give feedback.
-
Here's my puzzle that I'm having trouble solving: I have a
BlockingQueue
that I'm interacting with that is periodically being added to by a very large and expensive operation with the result of that operation. Each time a result is added to thisBlockingQueue
, I'd like to also publish that result through an endpoint. Then my web page can asynchronously update the page based on each result as we get it.In general, it looks like the solution I want for this is to use Server-Sent Events. Sure, no problem. Except I'm not sure how to populate my
Multi
based on periodically checking if anything's been added to myBlockingQueue
on another thread yet.Is this something that's possible? Or do I need to emit the results stored in this Queue some other way? Either way, my goal is to emit each result as it comes in, rather than waiting for the potentially hundreds or thousands of results to slowly fill the Queue and returning the massive list of results at the end.
Thanks ahead of time.
Beta Was this translation helpful? Give feedback.
All reactions