Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending JMS messages in a Spring WebFlux reactive handler: is it blocking?

Is this the correct way to handle reactively? I see 2 threads one reactive nio which is until and including flatMap(fareRepo::save). The other thread is computations thread which starts from sending message and goes on till ServerResponse.build(). My question is this correct way to handle request reactively? Note: that fareRepo is reactive couchbase repo. thanks

return request.bodyToMono(Fare.class).flatMap(fareRepo::save).flatMap(fs -> {
            logger.info("sending message: {}, to queue", fs.getId());
            jmsTemplate.send("fare-request-queue", (session) -> session.createTextMessage(fs.getId()));
            return Mono.just(fs);
        }).flatMap(fi -> ServerResponse.created(URI.create("/fare/" + fi.getId())).build());
like image 201
jzqa Avatar asked Apr 19 '18 07:04

jzqa


1 Answers

I'm assuming you're using Spring Framework's JmsTemplate implementation, which is blocking.

Without more context, we can only assume that you have a blocking operation in the middle of a reactive operator and that this will cause issues in your application.

like image 183
Brian Clozel Avatar answered Oct 12 '22 05:10

Brian Clozel