spring-integration-kafka消费者需要很长时间才能收到消息

时间:2015-07-15 16:44:35

标签: java spring spring-integration apache-kafka

我在项目中使用spring-integration-kafka,我可以很好地制作和使用消息。

我有1个制作人,1个高级消费者,1个分区用于我的主题。

当我发送5毫秒/秒时,消费者需要1秒才能开始接收消息。 但是,当我尝试使用多线程向kafka发送大约300毫秒/秒时,我看到消费者需要很长时间才能开始接收消息,大约5-10秒。并且发送较大的消息,较慢的消费者开始接收消息。我还尝试添加一些配置以减少延迟时间,但似乎没有效果。

所以有任何想法或建议可以帮我解决这个问题吗?我希望它始终需要0-1秒才能开始接收消息。非常感谢。

这是消费者配置:

 <int:channel id="inputFromKafka">
            <int:dispatcher task-executor="kafkaMessageExecutor" />
        </int:channel>

        <int-kafka:zookeeper-connect id="zookeeperConnect"
            zk-connect="127.0.0.1:2181" zk-connection-timeout="6000"
            zk-session-timeout="6000" zk-sync-time="2000" />

        <int-kafka:inbound-channel-adapter
            id="kafkaInboundChannelAdapter" 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>


        <bean id="consumerProperties"
            class="org.springframework.beans.factory.config.PropertiesFactoryBean">
            <property name="properties">
                <props>
                    <prop key="auto.offset.reset">smallest</prop>
                    <prop key="socket.receive.buffer.bytes">1048576</prop>
                    <prop key="fetch.message.max.bytes">5242880</prop>
                    <prop key="auto.commit.interval.ms">10</prop>
                </props>
            </property>
        </bean>

        <int-kafka:consumer-context id="consumerContext"
            consumer-timeout="1000" zookeeper-connect="zookeeperConnect"
            consumer-properties="consumerProperties">
            <int-kafka:consumer-configurations>
                <int-kafka:consumer-configuration
                    group-id="defaultGp" max-messages="10000">
                    <int-kafka:topic id="testTopic" streams="4" />
                </int-kafka:consumer-configuration>
            </int-kafka:consumer-configurations>
        </int-kafka:consumer-context>

        <task:executor id="kafkaMessageExecutor" pool-size="0-10"
            keep-alive="120" queue-capacity="500" />

        <int:outbound-channel-adapter channel="inputFromKafka"
            ref="kafkaConsumer" method="processMessage" />

制片人:

<int:publish-subscribe-channel id="inputToKafka" />

<int-kafka:outbound-channel-adapter
    id="kafkaOutboundChannelAdapter" kafka-producer-context-ref="kafkaProducerContext"
    auto-startup="true" order="1" channel="inputToKafka" />
<int-kafka:producer-context id="kafkaProducerContext"
    producer-properties="producerProps">
    <int-kafka:producer-configurations>
        <int-kafka:producer-configuration 
            broker-list="127.0.0.1:9092"
            async="true" topic="testTopic"
            key-class-type="java.lang.String" 
            key-encoder="encoder"
            value-class-type="java.lang.String" 
            value-encoder="encoder"
            compression-codec="default" />
    </int-kafka:producer-configurations>
</int-kafka:producer-context>

<util:properties id="producerProps">
    <prop key="queue.buffering.max.ms">500</prop>
    <prop key="topic.metadata.refresh.interval.ms">360000</prop>
    <prop key="queue.buffering.max.messages">10000</prop>
    <prop key="retry.backoff.ms">100</prop>
    <prop key="message.send.max.retries">5</prop>
    <prop key="send.buffer.bytes">5242880</prop>
    <prop key="socket.request.max.bytes">104857600</prop>
    <prop key="socket.receive.buffer.bytes">1048576</prop>
    <prop key="socket.send.buffer.bytes">1048576</prop>
    <prop key="request.required.acks">1</prop>
</util:properties>

<bean id="encoder"
    class="org.springframework.integration.kafka.serializer.common.StringEncoder" />


<task:executor id="taskExecutor" pool-size="5"
    keep-alive="120" queue-capacity="500" />

0 个答案:

没有答案