简体   繁体   中英

How to invoke reactive service inside JmsListener without blocking?

@Component
@RequiredArgsConstructor
public class EventListener {
    
    private final EventProcessingService eventProcessingService;

    @JmsListener(destination = "inputQueue", constainerFactory = "myContainerFactory)
    public void receiveMessage(Message message) {
       eventProcessingService(message).block(); // return Mono<Void>
    }

}

I have some Listener that listens to the queue and when messages come in it calls the reactive method of the service (EventProcessingService). I would like to know what happens when I block execution of a reactive service, can this lead to errors?

if your application is the one consuming the messages, the most appropriate would be to call subscribe() .

Subscribe should be used if your application is the final destination, you have not posted what eventProcessingService actually does so can't really tell.

All code can lead to errors, it depends on how your error handling look's like. Subscribe itself wont throw any errors, but you can choose to handle errors differently.

Here you can see different examples on how you wish to handle errors, and if you want to log errors. etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM