0
votes

Currently my task is to stop my spring boot app if the messaging queue fails to connect 5 times. I have found great use of

DefaultJmsListenerContainerFactory.setBackOff()

This will successfully stop the container after 5 failed attemps however when I use

@JmsListener(containerFactory="myFactory")

I am not explicitly creating the container and spring is doing it for me. So how can I check if the container shut down in order to close the spring boot app?

1
So is "myFactory" a custom container factory? If so are you creating it with a bean method? Can you call the setBackOff in your container factory bean method?Hopey One

1 Answers

0
votes
import javax.jms.ConnectionFactory;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;

    @Autowired
    private ConnectionFactory connectionFactory;

    @Bean("myFactory")
    public DefaultJmsListenerContainerFactory myCustomisedListenerFactory() {
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory);
        // interval, max number of attempts
        factory.setBackOff(new FixedBackOff(1000, 5));
        return factory;
    }