StartingDev
StartingDev

Reputation: 91

Spring DSL: Sending error message to JMS queue. Get an error 'one-way 'MessageHandler' and it isn't appropriate to configure 'outputChannel''

I must be missing something very basic in the flow definition. Getting this error

is a one-way 'MessageHandler' and it isn't appropriate to configure 'outputChannel'. This is the end of the integration flow.

My theory is that since adapter is one-way component, there is no output generated in the handle step of the flow. That is why this is causing a runtime error. But, not sure how else to define this simple flow.

Code:

@Autowired
private JmsMessagingTemplate jmsMessagingTemplate;

@Bean
public Queue errorQueue() {
    return new ActiveMQQueue(fatalQueue);
}
@Bean
public DirectChannel errorChannel() {
    return new DirectChannel();
}
@Bean
public IntegrationFlow handleErrors() {
    return IntegrationFlows
            .from(errorChannel())
            .handle(x -> System.out.println("error handling invoked.x="+x))
            .handle(Jms.outboundAdapter(jmsMessagingTemplate.getConnectionFactory()).destination(fatalQueue))
            .get();
}

And, the stacktrace says:

Caused by: org.springframework.beans.factory.BeanCreationException: The 'currentComponent' (MessageReceiver$$Lambda$1/1495414981@76c52298) is a one-way 'MessageHandler' and it isn't appropriate to configure 'outputChannel'. This is the end of the integration flow.
  at org.springframework.integration.dsl.IntegrationFlowDefinition.registerOutputChannelIfCan(IntegrationFlowDefinition.java:2630) ~[spring-integration-java-dsl-1.1.0.RELEASE.jar:na]
  at org.springframework.integration.dsl.IntegrationFlowDefinition.register(IntegrationFlowDefinition.java:2554) ~[spring-integration-java-dsl-1.1.0.RELEASE.jar:na]
  at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:1136) ~[spring-integration-java-dsl-1.1.0.RELEASE.jar:na]
  at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:1116) ~[spring-integration-java-dsl-1.1.0.RELEASE.jar:na]
  at org.springframework.integration.dsl.IntegrationFlowDefinition.handle(IntegrationFlowDefinition.java:863) ~[spring-integration-java-dsl-1.1.0.RELEASE.jar:na]

Upvotes: 2

Views: 1046

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121552

Your issue is here:

.handle(x -> System.out.println("error handling invoked.x="+x))

The StackTrace talks about that exactly.

And it isn't a surprise. your Lambda is like this impl:

.handle(new MessageHandler() {

        public void handleMessage(Message<?> message) throws MessagingException {
               System.out.println("error handling invoked.x="+x);
        }
})

Pay attention to the void return type. So, there is nothing to pass in the downstream.

To fix it you should do something like thing:

.handle((p, h) -> {
        System.out.println("error handling invoked.x=" + new MutableMessage(p, h));
        return p;
 })

Where it is a GenericHandler implementation.

Your .handle(Jms.outboundAdapter()) is good here. It is really the end of the flow.

Upvotes: 5

Related Questions