Closed
Description
Affects Version(s): 5.1.4-RELEASE
Jms.inboundGateway appears to ignore the errorChannel specified
@RunWith(SpringRunner.class)
@SpringBootTest(classes = JmsInboundGatewayWithoutWorkaroundTest.Flow.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class JmsInboundGatewayWithoutWorkaroundTest {
@Autowired
JmsTemplate jmsTemplate;
@Before
public void setUp() {
jmsTemplate.setReceiveTimeout(1000);
}
@Test
public void error() {
jmsTemplate.convertAndSend("requestQ", "fail");
assertThat(jmsTemplate.receiveAndConvert("replyQ"), equalTo("error"));
}
@SpringBootApplication
public static class Flow {
@Autowired
ConnectionFactory connectionFactory;
@Bean
JmsInboundGateway jmsInboundGateway() {
return Jms.inboundGateway(connectionFactory)
.destination("requestQ")
.requestChannel(inFlowChannel())
.defaultReplyQueueName("replyQ")
.errorChannel(errorChannel())
.get();
}
@Bean
DirectChannel inFlowChannel() {
return MessageChannels.direct().get();
}
@Bean
DirectChannel errorChannel() {
return MessageChannels.direct().get();
}
@Bean
IntegrationFlow inFlow() {
return IntegrationFlows.from(inFlowChannel())
.handle((p,h) -> {
throw new RuntimeException("whoops");
})
.get();
}
@Bean
IntegrationFlow errorFlow() {
return IntegrationFlows.from(errorChannel())
.enrichHeaders(h -> h.headerExpression(MessageHeaders.REPLY_CHANNEL, "payload.failedMessage.headers['"+MessageHeaders.REPLY_CHANNEL+"']"))
.handle((p,h) -> "error")
.get();
}
}
}
If I set the errorChannel on the underlying Listener then this example works as expected:
@Bean
JmsInboundGateway jmsInboundGateway() {
JmsInboundGateway inboundGateway = Jms.inboundGateway(connectionFactory)
.destination("requestQ")
.requestChannel(inFlowChannel())
.defaultReplyQueueName("replyQ")
.errorChannel(errorChannel())
.get();
inboundGateway.getListener().setErrorChannel(errorChannel());
return inboundGateway;
}
I suspect that the JmsInboundGateway should override setErrorChannel in the same way it does for setRequestChannel so that the errorChannel is also set on the underlying Listener.
Appreciate your thoughts.