-1

We are using rabbitmq and our producers and consumers were developed using spring-boot-starter-amqp (spring-rabbit 1.5.6.RELEASE),

We've had some deadlocks in our consumers in production and, when it happened, we needed restart our consumers to process new messages again. Probably this problem is happening because some messages are blocked by another transaction in one of our consumers. We started an investigation to found these deadlocks but we have a complex context and is little hard to found dead-locks problems, so I'd like ask:

There is a way to put some timeout when we process our messages in our spring-boot application to help-us to abort just one message don't bloking all messages in our consumers.

our code:

AmqpConfig.class{
    @Bean
    public SimpleMessageListenerContainer container(ConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) {
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.setQueues(consumerQueue());
        container.setMessageListener(listenerAdapter);
        return container;
    }

    @Bean
    public MessageListenerAdapter listenerAdapter(Receiver receiver) {
        MessageListenerAdapter listener = new MessageListenerAdapter(receiver);
        listener.addQueueOrTagToMethodName(consumerQueue().getName(), "consumerListener");
        return listener;
    }


    @Bean
    public Queue consumerQueue() {
        return new Queue("some.consumer", true, false, false, null);
    }
}

Receiver.class{
    //method than I'd like put some timeout to process.
    public String consumerListener(String message) {
        //code probably causing deadlock.
    }
}

Thanks for your help.

1 Answers1

0

If the deadlocks are on synchronized blocks or methods, you are out of luck; they are not interruptible.

You have to solve the deadlocks.

If you can change them to use java.util.concurrent.locks.Locks instead, you use tryLock() with a timeout.

There is nothing the framework can do to help you with this problem.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179