Spring Itegration. Send Slack notification WebFlux

94 Views Asked by At

I need to send a slack message in many parts of the flow indication the file processing information and continue with the main flow.

I didn't found a totally straightforward way of doing it

Here my solution up to now:

Declare a queue channel to receive the messages that need to be sent

@Bean
MessageChannel slackChannel() {
  return MessageChannels.queue(SLACK_CHANNEL).get();
}

Every message in that channel is will be sent to Slack (applying some transformation before sending it)

@Bean
    IntegrationFlow startFlow() {

        return IntegrationFlows
                .from(FILE_CHANNEL)
                .filter(myFilter)
                .handle(myService, "doSomething")
                .transform(doSomeTransformation)

                .channel(SLACK_CHANNEL)

                .split()
                .aggregate(myAggregator)
                .transform(anotherTransformer)
                .channel(ANOTHER_CHANNEL)
                .get();
    }

Here the slack flow

@Bean
    IntegrationFlow sendFileProcessingInfo() {
        return IntegrationFlows
                .from(SLACK_CHANNEL)
                .transform(Message.class, this::prepareSlackMessage)
                .handle(WebFlux.outboundGateway(m ->
                        UriComponentsBuilder.fromUriString(slackConfigurationProperties.getUrl())
                                .build()
                                .toUri())
                .httpMethod(HttpMethod.POST)
                .expectedResponseType(String.class))
                .log()
                .get();
    }

One of the problems is that the flow doesn't continue after sending the message to the SLACK_CHANNEL in the middle of the main flow.

Another problem is that sendFileProcessingInfo apparently is never activated

Additionally, I've some doubts that expectedResponseType must be String.

So, what should be the most appropriate solution to send HTTP messages in the middle of the flow? and What could be the cause of the issues?

Also, Doing the transformation to prepare the slack message will change the object of the main flow?

I'll appreciate any help on this.

Thanks!

0

There are 0 best solutions below