首页 > 解决方案 > 春季迭代。发送 Slack 通知 WebFlux

问题描述

我需要在流程的许多部分发送一条松弛消息,指示文件处理信息并继续主流程。

我没有找到一种完全直接的方法

到目前为止,我的解决方案是:

声明一个队列通道来接收需要发送的消息

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

该通道中的每条消息都将发送到 Slack(在发送之前应用一些转换)

@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();
    }

这里是松弛流

@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();
    }

问题之一是在将消息发送到主流程中间的 SLACK_CHANNEL 后流程不会继续。

另一个问题是 sendFileProcessingInfo 显然从未激活

另外,我怀疑expectedResponseType 必须是String。

那么,在流程中间发送 HTTP 消息的最合适的解决方案应该是什么?问题的原因可能是什么?

另外,为准备松弛消息进行转换会改变主要流程的对象吗?

我会很感激这方面的任何帮助。

谢谢!

标签: spring-webfluxspring-integration-dslmessage-channel

解决方案


推荐阅读