I am developing an API in spring-integration using DSL, this how it works

JDBC Polling Adapter initiates the flow and gets some data from tables and send it to DefaultRequestChannel, from here the message is handled/flowing thru various channels.

Now I am trying to
1. send a email, if any errors (e.g connectivity issue, bad record found while polling the data) occurred/detected in my error channel.

  1. After sending email to my support group, I want to suspend my flow for 15 mins and then resume automatically.

I tried creating a sendEmailChannel (recipient of my errorChannel), it doesn't work for me. So just created a transformer method like below

this code is running fine, but is it a good practice? @

@Transformer(inputChannel="errorChannel", outputChannel="suspendChannel")
public Message<?> errorChannelHandler(ErrorMessage errorMessage) throws RuntimeException, MessagingException, InterruptedException {

Exception exception = (Exception) errorMessage.getPayload();
    String errorMsg = errorMessage.toString();
    String subject = "API issue";
    if (exception instanceof RuntimeException) {
        errorMsg = "Run time exception";
        subject = "Critical Alert";
    }
    if (exception instanceof JsonParseException) {
        errorMsg = ....;
        subject = .....;
    }

    MimeMessage message = sender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message);
    helper.setFrom(senderEmail);
    helper.setTo(receiverEmail);
    helper.setText(errorMsg);
    helper.setSubject(subject);
    sender.send(message);
    kafkaProducerSwitch.isKafkaDown());
    return MessageBuilder.withPayload(exception.getMessage())

            .build();
}

I am looking for some better way of handling the above logic. And also any suggestions to suspend my flow for few mins.

0 Answers