vendredi 28 juillet 2017

Spring boot and rabbitmq integration, how to recover on component failure?

I have a spring rest app with rabbit as messaging middle ware. When the app accepts incoming rest request, it replies to the user meanwhile it does some extra processing asynchronously, generates a new message and puts it on rabbit. From there, some consumers read the message and deliver it to the external system. Now, there is a case that the rabbit server itself may be down. To handle that kind of failure, I have a blocking queue (of course with an adjustable size)

 @Bean
public TaskExecutor taskExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(5);
    executor.setMaxPoolSize(10);
    executor.setQueueCapacity(25);

    return executor;
}

The queue will be able to handle some messages until rabbit comes online. But if it takes too long and the requests exceeds the queue size, then it is going to fail. Now the question is, are there a ways that I can improve this and make it more efficient? What is the industry best practice? Are there any patterns for that scenario?

Aucun commentaire:

Enregistrer un commentaire