Can I allow multiple http clients to consume a Flowable stream of data with resteasy-rxjava2 / quarkus?

丶灬走出姿态 提交于 2020-05-30 09:48:38

问题


Currently I am able to see the streaming values exposed by the code below, but only one http client will receive the continuous stream of values, the others will not be able to. The code, a modified version of the quarkus quickstart for kafka reactive streaming is:

@Path("/migrations")
public class StreamingResource {
    private volatile Map<String, String> counterBySystemDate = new ConcurrentHashMap<>();

    @Inject
    @Channel("migrations")
    Flowable<String> counters;

    @GET
    @Path("/stream")
    @Produces(MediaType.SERVER_SENT_EVENTS) // denotes that server side events (SSE) will be produced
    @SseElementType("text/plain") // denotes that the contained data, within this SSE, is just regular text/plain data
    public Publisher<String> stream() {
        Flowable<String> mainStream = counters.doOnNext(dateSystemToCount -> {
            String key = dateSystemToCount.substring(0, dateSystemToCount.lastIndexOf("_"));
            counterBySystemDate.put(key, dateSystemToCount);
        });
        return fromIterable(counterBySystemDate.values().stream().sorted().collect(Collectors.toList()))
                .concatWith(mainStream)
                .onBackpressureLatest();
    }
}

Is it possible to make any modification that would allow multiple clients to consume the same data, in a broadcast fashion?

I guess this implies letting go of backpressure, because that would imply a state per consumer?

I saw that Observable is not accepted as a return type in the resteasy-rxjava2 for the Server Side Events media-tpe.

Please let me know any ideas,

Thank you

Please find the full code in Why in multiple connections to PricesResource Publisher, only one gets the stream?

来源:https://stackoverflow.com/questions/61896505/can-i-allow-multiple-http-clients-to-consume-a-flowable-stream-of-data-with-rest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!