ErrorHandling in Spring Java Dsl Integration

I am wondering what is the proper way to use serviceActivators in SI Java Dsl to handle errors. I have Spring xml config integration:

<jms:message-driven-channel-adapter id="messageIn" auto-startup="false"
                                    container="messageNotificationJms" channel="messageChannel"
                                    error-channel="customErrorChannel"/>

<channel id="messageChannel"/>

<chain input-channel="messageChannel">
    <!-- some logic and service-activator -->
</chain>

<channel id="customErrorChannelTpm"/>

<chain input-channel="customErrorChannel" output-channel="nullChannel">
    <service-activator ref="errorService" method="stopEndpoints" />
</chain>

But now I'm trying to use SI Java DSL to configure this context, so I create this configuration

@Configuration
@EnableIntegration
public class SIConfig {

    @Autowired
    AbstractMessageListenerContainer messageNotificationJms;

    @Autowired
    ErrorService errorService;

    @Bean
    public MessageChannel messageChannel() {
        return MessageChannels.direct("messageChannel").get();
    }

    @Bean
    public MessageChannel customErrorChannel() {
        return MessageChannels.direct("customErrorChannel").get();
    }

    @Bean
    public JmsMessageDrivenChannelAdapter messageIn() {
        return Jms.messageDriverChannelAdapter(messageNotificationJms)
                .id("messageIn")
                .autoStartup(false)
                .outputChannel(messageChannel())
                .errorChannel(customErrorChannel())
                .get();
    }


    @Bean
    public IntegrationFlow customErrorFlow() {
        return IntegrationFlows.from(customErrorChannel())
            //.handle () ?????????????????????????
        .get();
    }

    @Bean
    public IntegrationFlow messageFlow() {
        //some logic
    }

}

As parameters of the descriptor method, I tried using lambda expressions like this

 .handle(message -> errorService.stopEndpoints(message))

but there was a compilation error due to parameter types and return type.

I have one non-obvious option without compilation errors, but I'm not sure if it will work correctly in the environment. Is it correct:

  .<ErrorMessage>handle((payload, headers) -> {
     errorService.stopEndpoints(payload);
     return null;
})

Also, my class is ErrorHandler.

@Component
public class ErrorService implements ErrorHandler {

    @Override
    public void handleError(Throwable t) {
        stopEndpoints(t);
    }

    public void stopEndpoints(ErrorMessage errorMessage) {
        Throwable throwable = errorMessage.getPayload();
        stopEndpoints(throwable);

    }

    private void stopEndpoints(Throwable t) {
        //stoppingEndpoints
    }

}

EDIT: I am using Spring Framework 4.1.6, Spring Integration 4.1.3 and SI Java DSL 1.0.1

+4
source share
1

handle(String beanName, String methodName):

handle("errorService", "stopEndpoints");

handle("errorService", "handleError");

.

+3

All Articles