kisileno
kisileno

Reputation: 787

How to turn off automatic retry in Spring Integration Jms.inboundGateway

I am using spring 4.2.4.RELEASE and spring-integration-java-dsl:1.1.2.RELEASE

I have Jms.inboundGateway and some transformer. When transformer fails to transform a message, inbound gateway retries again and again. But I want to stop the entire flow in case of exception.
Is it possible to do?

This is my flow configuration:

@Bean
public IntegrationFlow nonStop {
    return IntegrationFlows
            .from(Jms.inboundGateway(emsConnectionFactory)
                    .destination(myDestination)
                    .configureListenerContainer(spec -> spec
                            .sessionTransacted(true)
                            .subscriptionDurable(true)
                            .durableSubscriptionName(durableSubscriptionName)
                            .errorHandler((ErrorHandler) t -> {
                                t.printStackTrace();
                                throw new RuntimeException(t);
                            }))
                    .errorChannel(errorChannel)
                    .autoStartup(true)
                    .id(myNonStoppableFlow))
            .filter(...)
            .transform(...)
            .handle(Jms.outboundAdapter(emsConnectionFactory)
                             .destination(myOnotherDestination))
            .get();
}

One interesting notice. When errorHandler swallows an exception inbound gateway retires without any delay. When it throws Runtime exception there is delay about 5 seconds (which is not configured anywhere).

Upvotes: 2

Views: 1281

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121272

That retry in JMS is called like redelivery: http://www.javaworld.com/article/2074123/java-web-development/transaction-and-redelivery-in-jms.html.

So, any downstream exception makes for your message rollback and redelivery, which can be configured on Broker for the destination.

Actually if your .errorChannel(errorChannel) flow doesn't re-throw the exception, it will be treated as a successful handling and as commit.

From other side you should reconsider if you really need there a Jms.inboundGateway(). Because this one requires a reply, which doesn't look possible with your Jms.outboundAdapter() in the end.

Upvotes: 1

Related Questions