0

I am currently trying to consume kafka events , I am able to do it, but once events are consumed, it needs to be published to UI after some minimal processing, For publishing the captured events from Kafka I am using project reactor Sinks, sinks.many.multicast.onBackPressureBuffer, and streaming it to UI with SSE, keeping the produces to TEXT_EVENT_STREAM, and I am also using ExecuteOn (TaskExecutors.IO) since this will be a long running task as it is SSE. But I am seeing a strange behavior like only one call gets the response , concurrent requests made for the same API does not get hit, it is executing one after the other like if the first subscribed call stops listening the second call which was hit long back becomes active, I see the threads on which these concurrent requests were received are different but still they are like blocking although the response type is Flux, Does anyone what might be causing this issue or any other better approach for this?

I am expecting that every API request is a subscriber and should run independently without depending on the other subscriber to complete.

+++++++++++++++++++++++++++++++++++++++
   
@Singleton
 class OrderEmitter {
      private Sinks.Many<String> sink = Sinks.many().multicast().onBackpressureBuffer();
        private Flux<String> flux = sink.asFlux();
    
        public Sinks.EmitResult emitOrder(Order order) {
            return this.sink.tryEmitNext(order);
        }
    
        public Flux<String> getOrderFlux() {
         // this may contain additional processing logic
            return order;
        }
    }
    +++++++++++++++++++++++++++++++++++
    
    @Inject
    OrderEmitter orderEmitter;
    
    @kafkaConsumer
    public void emitOrder(Order order) {
     orderEmitter.emit(order);
    }
++++++++++++++++++++++++++++++++++++++++++++
Inside controller layer
@Controller
class Controller {

@Inject
OrderEmitter orderEmitter;

@Get(produces=MediaType.TEXT_EVENT_STREAM)
public Flux<Order> getOrders() {
return orderEmitter.getOrderFlux();
}
}
techSavvy
  • 1
  • 1
  • 3

0 Answers0