0

我正在使用SpringXD,并且我有以下配置:

  • spring-integration-kafka 2.1.0.RELEASE
  • 卡夫卡客户端 0.10.0.1
  • 卡夫卡 0.10.xx
  • spring-xd-1.3.1.RELEASE

我的 xml 文件中有以下配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:int-kafka="http://www.springframework.org/schema/integration/kafka"
    xmlns:task="http://www.springframework.org/schema/task"
    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">


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

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

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

</beans>

这是我用来启动/停止通道的 Java 类:

package com.kafka.source.logic;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Configuration
@EnableScheduling
@ImportResource("classpath:/config/kafka-source-context.xml")
public class KafkaSourceRetry {

    @Autowired
    MessageChannel input;

    @Scheduled(cron="*/50 * * * * *")
    void startAdapter(){
        //CODE COMMENTED OUT TO MAKE SURE THE ADAPTER IS NOT BEING STARTED
        //EVEN IF I UNCOMMENT THE CODE, THE 50 secs defined related to the cron are not respected.
        //That is, if I send a message to the topic, it is inmediately consumed
        //input.send(new GenericMessage<String>("@kafka-inbound-channel-adapter-testing.start()"));
    }
}

然后我创建了一个基本流来检查我发送到该主题的某些消息是否通过

stream create --name bridgeStream --definition "kafkaSourceLatestApi_v2|bridge|file" --deploy

我检查了创建的文件,它包含了我发送到 Kafka 主题的所有消息:

hola_que_tal que_bonito bridgeStream.out (END)

同样在日志中我发现了这个:

2017-04-10T22:37:06-0300 1.3.1.RELEASE INFO DeploymentsPathChildrenCache-0 support.DefaultLifecycleProcessor - 在阶段 0 中启动 bean 2017-04-10T22:37:06-0300 1.3.1.RELEASE DEBUG DeploymentsPathChildrenCache-0 支持.DefaultLifecycleProcessor - 启动 bean 'container1' 类型 [class org.springframework.kafka.listener.KafkaMessageListenerContainer] 2017-04-10T22:37:06-0300 1.3.1.RELEASE DEBUG DeploymentsPathChildrenCache-0 support.DefaultLifecycleProcessor - 成功启动 bean ' container1' 2017-04-10T22:37:06-0300 1.3.1.RELEASE INFO DeploymentsPathChildrenCache-0 support.DefaultLifecycleProcessor - 在阶段 100 中启动 bean 2017-04-10T22:37:06-0300 1.3.1.RELEASE DEBUG DeploymentsPathChildrenCache- 0 support.DefaultLifecycleProcessor - 启动 bean 'kafka-inbound-channel-adapter-testing'类型 [class org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter] 2017-04-10T22:37:06-0300 1.3.1.RELEASE INFO DeploymentsPathChildrenCache-0 inbound.KafkaMessageDrivenChannelAdapter - 开始 kafka-inbound-channel-adapter-testing 2017-04-10T22:37:06-0300 1.3.1.RELEASE DEBUG DeploymentsPathChildrenCache-0 support.DefaultLifecycleProcessor -成功启动 bean 'kafka-inbound-channel-adapter-testing'

我的问题是:为什么频道会自动启动?

4

1 回答 1

1

它就是这样设计的;所有模块都将自动启动设置为 false,因此它们不会乱序启动;当您部署流时,各个模块会从右到左进行部署和启动。

部署/取消部署是启动/停止流的方式。

ModuleDeployer

于 2017-04-11T02:09:32.060 回答