Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot spring集成-如何将拆分的行聚合为一批x?_Spring Boot_Spring Integration_Spring Integration Aws - Fatal编程技术网

Spring boot spring集成-如何将拆分的行聚合为一批x?

Spring boot spring集成-如何将拆分的行聚合为一批x?,spring-boot,spring-integration,spring-integration-aws,Spring Boot,Spring Integration,Spring Integration Aws,我们需要将活动发送到kinesis,由于aws定价,我们计划将记录分批发送到kinesis 我们读入csv文件,然后使用文件拆分器吐出行并将每行转换为json 因此,在转换为json之后,我们如何将这些行批处理为每批25行,以便我们的kinesis serviceActivator可以发送该批 任何例子都将不胜感激 <int-file:splitter id="fileLineSplitter" input-channel="fileI

我们需要将活动发送到kinesis,由于aws定价,我们计划将记录分批发送到kinesis

我们读入csv文件,然后使用文件拆分器吐出行并将每行转换为json

因此,在转换为json之后,我们如何将这些行批处理为每批25行,以便我们的kinesis serviceActivator可以发送该批

任何例子都将不胜感激

    <int-file:splitter id="fileLineSplitter"
                       input-channel="fileInputChannel"
                       output-channel="splitterOutputChannel"
                       markers="true" />


<int:transformer id="csvToDataCdrTransformer"
                     ref="dataCdrLineTransformer"
                     method="transform"
                     input-channel="lineOutputChannel"
                     output-channel="dataCdrObjectInputChannel">
    </int:transformer>


    <int:object-to-json-transformer input-channel="dataCdrObjectInputChannel"
                                    output-channel="kinesisSendChannel">
        <int:poller fixed-delay="50"/>
    </int:object-to-json-transformer>

有什么想法吗?

为此,您肯定需要一个
,带有
发布策略表达式=“25”
在完成时过期组=“true”
,以便在发布一个组后为相同的
相关键
形成一个新组

不,请确定为什么需要
markers=“true”
,但如果不需要,则
会填充相应的相关头。因此,您甚至可以考虑只依赖默认的分割和默认聚合。

此外,您应该考虑将一个聚合器的结果转换为JSON。它发出一个

列表
。将整个列表序列化为JSON非常有效。另外,在发送到Kinesis之前,您可能需要再进行一次转换

因此,配置的原型应如下所示:

<int-file:splitter id="fileLineSplitter"
                   input-channel="fileInputChannel"
                   output-channel="splitterOutputChannel"/>

<int:transformer id="csvToDataCdrTransformer"
                 ref="dataCdrLineTransformer"
                 method="transform"
                 input-channel="lineOutputChannel"
                 output-channel="aggregateChannel">
</int:transformer>

<int:aggregator input-channel="aggregateChannel" 
                output-channel="toJsonChannel"
                expire-groups-upon-completion="true" />

<int:object-to-json-transformer input-channel="toJsonChannel"
                                output-channel="kinesisSendChannel"/>

这样,整个文件将被视为一个批处理。您将其拆分,处理每一行,将它们聚合回列表,然后在发送到Kinesis之前转换为JSON


在此,我想请您提出一个JIRA,添加
ObjectToJsonTransformer.ResultType.BYTES
模式,以便更高效地使用基于
字节[]的下游组件
类似
运动消息处理程序

使用标记=“true”所以我们知道它是文件的结尾,所以我们可以将它重命名为“.done”。我应用了你的解决方案,它确实有效。但是,我不得不在拆分器和转换器之间放置一个路由器,我发现了错误。请您帮助我对问题进行“编辑”。如果您的
transform
方法返回
Message
,您负责将输入头复制到输出消息。如果您只返回新的有效负载,框架将复制头-拆分器默认情况下会添加一个
correlationId
头。我添加了一个路由器,请参阅上面编辑部分2中的路由器代码,并获取“不允许空相关”错误。上面的方法DeterminateTargetChannels(…)从Splitter接收到一条带有correlationId的消息,当路由器返回一个通道时,我如何将correlationId作为返回通道的一部分传递回去?我正在使用路由器,以便知道文件何时结束,因此markers=true,以便我可以重命名文件。你能推荐另一种重命名文件的方法吗?另外,如果我移除路由器并从拆分器转到Trnasformer,那么它将按照@Artem建议的那样工作。使用
markers=true
时,您必须手动打开
filespliter
上的
correlation
apply sequence=“true”
<int:router ref="fileMarkerCustomRouter" inputchannel="splitterOutputChannel" default-output-channel="lineOutputChannel"/>
 @Override
    protected Collection<MessageChannel> determineTargetChannels(Message<?> message) {
        Collection<MessageChannel> targetChannels = new ArrayList<MessageChannel>();

        if (isPayloadTypeFileMarker(message)) {

            FileSplitter.FileMarker payload = (FileSplitter.FileMarker) message.getPayload();

            if (isStartOfFile(payload)) {

                targetChannels.add(nullChannel);

            } else if (isEndOfFile(payload)) {

                targetChannels.add(fileProcessedChannel);
            }
        }
        return targetChannels;
    }
Caused by: java.lang.IllegalStateException: Null correlation not allowed.  Maybe the CorrelationStrategy is failing?
<int-file:splitter id="fileLineSplitter"
                   input-channel="fileInputChannel"
                   output-channel="splitterOutputChannel"/>

<int:transformer id="csvToDataCdrTransformer"
                 ref="dataCdrLineTransformer"
                 method="transform"
                 input-channel="lineOutputChannel"
                 output-channel="aggregateChannel">
</int:transformer>

<int:aggregator input-channel="aggregateChannel" 
                output-channel="toJsonChannel"
                expire-groups-upon-completion="true" />

<int:object-to-json-transformer input-channel="toJsonChannel"
                                output-channel="kinesisSendChannel"/>