Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/371.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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
Java Spring集成与集成;Kafka使用者:在成功获取记录后立即停止消息驱动的通道适配器_Java_Spring_Spring Integration_Spring Xd_Spring Kafka - Fatal编程技术网

Java Spring集成与集成;Kafka使用者:在成功获取记录后立即停止消息驱动的通道适配器

Java Spring集成与集成;Kafka使用者:在成功获取记录后立即停止消息驱动的通道适配器,java,spring,spring-integration,spring-xd,spring-kafka,Java,Spring,Spring Integration,Spring Xd,Spring Kafka,我正在使用以下确认: spring集成kafka 2.1.0.0版本 卡夫卡客户端0.10.0.1 卡夫卡0.10.x.x spring-xd-1.3.1.释放 我为SpringXD创建了自定义Kafka源模块。我设置消费者逻辑和消息驱动通道适配器(与控制总线一起使用以停止通道适配器)。到现在为止,一直都还不错。此外,我还将其用作kafka属性,每次轮询获取10条记录 我想确保在成功获取所有记录(本例中为10条记录)后立即停止频道 因此,例如:我希望避免在并非所有记录都已成功获取和处理(即记

我正在使用以下确认:

  • spring集成kafka 2.1.0.0版本
  • 卡夫卡客户端0.10.0.1
  • 卡夫卡0.10.x.x
  • spring-xd-1.3.1.释放
我为SpringXD创建了自定义Kafka源模块。我设置消费者逻辑和
消息驱动通道适配器
(与
控制总线一起使用以停止通道适配器)。到现在为止,一直都还不错。此外,我还将其用作kafka属性,每次轮询获取10条记录

我想确保在成功获取所有记录(本例中为10条记录)后立即停止频道

因此,例如:我希望避免在并非所有记录都已成功获取和处理(即记录未发送到输出通道)时停止读取

有没有办法说出来

这是我的xml配置,以防万一:

xsi:schemaLocation=”http://www.springframework.org/schema/integration/kafka http://www.springframework.org/schema/integration/kafka/spring-integration-kafka.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">

[更新编号1] 我为什么要这样做? 详情如下:

  • 我想每隔Y分钟阅读卡夫卡主题中最多X条信息
  • 我使用
    max.poll.records
    确保每次轮询最多只能获取X条消息
  • 我想处理的一个场景是:如果在一个特定的消息轮询中,我轮询的消息少于X,会发生什么情况。这意味着我应该在不等待X消息的情况下停止频道,否则我将不得不等到将来的消息轮询到达那些X消息
这些是关于这个场景的一些细节。还有更多的场景,但我不想用同一个问题来混合

[第2次更新]

阿泰姆回答后的一些想法

  • 如果我不定义
    max.poll.records
    并等待达到Y分钟并统计X消息,然后停止该频道,会发生什么
  • 是否有些消息会因为无法读取而丢失,或者当我
    再次启动频道时,无法读取的消息会被读取

我希望避免将消息保留在内存中,这就是我使用
消息驱动通道适配器的原因
+
max.poll.records

我可以建议的是像
AtomicInteger
bean一样,它在每个处理的记录上增加,当达到阈值时,执行
stop()
对于您的
kafkainboundchanneladapter测试

在这种情况下,我如何控制正在处理的记录?我是说,我怎么知道我在处理一个特定的记录?在您提到的场景中,我唯一关心的是告诉您一条记录正在通过(只是通知),但如何告诉?不,我的意思是您可以对内部通道使用
wireltap
,并在其自身流中增加计数器。消息将按原样发送到流程。只需添加
我就看到了一个新问题。比如说
max.poll.records=10
。所以我预计会数到10条信息,然后停止频道。但出于某种原因,卡夫卡主题中只有不到10条消息(比如说4条消息)。然后,当我使用
有线点击
+
原子整数
时,如何判断我正在计数的消息是否属于当前轮询?类似的情况。只需确保选择正确的确认模式:这就是重点。你说对了!现在这个
xsi:schemaLocation="http://www.springframework.org/schema/integration/kafka http://www.springframework.org/schema/integration/kafka/spring-integration-kafka.xsd
    http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
                               http://www.springframework.org/schema/context
                       http://www.springframework.org/schema/context/spring-context.xsd">


<int:channel id="input_to_control_bus" />
<int:channel id="output" />

<context:component-scan base-package="com.kafka.source.logic" />


<int:control-bus id="my_control_bus" input-channel="input_to_control_bus" />

<int-kafka:message-driven-channel-adapter
    id="kafkaInboundChannelAdapterTesting" listener-container="container1"
    auto-startup="false" phase="100" send-timeout="5000" channel="output"
    mode="record" message-converter="messageConverter" />

<bean id="messageConverter"
    class="org.springframework.kafka.support.converter.MessagingMessageConverter" />

<!--Consumer -->
<bean id="container1"
    class="org.springframework.kafka.listener.KafkaMessageListenerContainer">
    <constructor-arg>
        <bean class="org.springframework.kafka.core.DefaultKafkaConsumerFactory">
            <constructor-arg>
                <map>
                    <entry key="bootstrap.servers" value="localhost:9092" />
                    <entry key="enable.auto.commit" value="false" />
                    <entry key="auto.commit.interval.ms" value="100" />
                    <entry key="session.timeout.ms" value="15000" />
                    <entry key="max.poll.records" value="3" />
                    <entry key="group.id" value="bridge-stream-testing" />
                    <entry key="key.deserializer"
                        value="org.apache.kafka.common.serialization.IntegerDeserializer" />
                    <entry key="value.deserializer"
                        value="org.apache.kafka.common.serialization.StringDeserializer" />
                </map>
            </constructor-arg>
        </bean>
    </constructor-arg>

    <constructor-arg>
        <bean class="org.springframework.kafka.listener.config.ContainerProperties">
            <constructor-arg name="topics" value="testing-topic" />
        </bean>
    </constructor-arg>
</bean>