Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.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 integration Spring集成kafka入站适配器聚合传入消息_Spring Integration_Apache Kafka - Fatal编程技术网

Spring integration Spring集成kafka入站适配器聚合传入消息

Spring integration Spring集成kafka入站适配器聚合传入消息,spring-integration,apache-kafka,Spring Integration,Apache Kafka,我有一个int-kafka:outbound channel adapter,我用它向kafka发送消息,然后用int-kafka:inbound channel adapter接收消息。沟通似乎很好,我可以发送和接收信息,但格式有点奇怪。我将单独向我的出站适配器发送消息,但当我收到消息时,我会返回一条消息,并将所有消息聚合到该消息的有效负载中 这就是我收到消息时消息负载的样子 [payload={mytopic={0=[string message 1,string message 2,str

我有一个
int-kafka:outbound channel adapter
,我用它向kafka发送消息,然后用
int-kafka:inbound channel adapter
接收消息。沟通似乎很好,我可以发送和接收信息,但格式有点奇怪。我将单独向我的出站适配器发送消息,但当我收到消息时,我会返回一条消息,并将所有消息聚合到该消息的有效负载中

这就是我收到消息时消息负载的样子

[payload={mytopic={0=[string message 1,string message 2,string message 3,string message 4,string message 5,…]},headers={id=3934de02-1f42-ab90-6aa5-9c15f3cd0b6e,timestamp=1439260669762}]

接收集成流如下所示

<int-kafka:inbound-channel-adapter
    id="kafkaInboundAdapter" kafka-consumer-context-ref="consumerContext"
    auto-startup="true" channel="inputFromKafka">
    <int:poller fixed-delay="10" time-unit="MILLISECONDS"
        max-messages-per-poll="5" />
</int-kafka:inbound-channel-adapter>

<int:channel id="inputFromKafka" />

<int:service-activator id="kakfaMessageHandler"
    input-channel="inputFromKafka">
    <bean class="com...broker.MessageHandler"></bean>
</int:service-activator>


我之所以在一条spring integration消息中接收所有聚合消息而不是发送给kafka的单独消息的原因。

KafkaHighLevelConsumerMessageSource与其他轮询
MessageSource
:通过一次轮询获取数据并将其作为
列表返回

在本例中,我们从卡夫卡
stream
阅读中得到以下结果:

Message<Map<String, Map<Integer, List<Object>>>>
消息
其中,
有效载荷
是卡夫卡
主题
s的
映射
,以及
分区
s和
消息
s的映射

如果在
consumerContext
上仅使用一个
主题
,则只需将顶级
映射
转换为其
分区
映射即可。或者,如果您只有一个
分区
,甚至可以继续转换到
有效负载
s列表。最后,您可以使用
拆分器


如果您想一个接一个地接收主题中的消息,并在它们出现时尽快接收,您应该查看

KafkaHighLevelConsumerMessageSource
与许多其他轮询
MessageSource
:通过一次轮询获取数据并将其作为
列表返回

在本例中,我们从卡夫卡
stream
阅读中得到以下结果:

Message<Map<String, Map<Integer, List<Object>>>>
消息
其中,
有效载荷
是卡夫卡
主题
s的
映射
,以及
分区
s和
消息
s的映射

如果在
consumerContext
上仅使用一个
主题
,则只需将顶级
映射
转换为其
分区
映射即可。或者,如果您只有一个
分区
,甚至可以继续转换到
有效负载
s列表。最后,您可以使用
拆分器

如果您想一个接一个地接收来自主题的消息,并在消息出现时尽快接收,您应该查看