Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.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 kafka消息驱动适配器不工作_Spring_Spring Integration_Apache Kafka - Fatal编程技术网

Spring kafka消息驱动适配器不工作

Spring kafka消息驱动适配器不工作,spring,spring-integration,apache-kafka,Spring,Spring Integration,Apache Kafka,要使用kafka:消息驱动的通道适配器使用消息 在以下通道中生成消息: 标题['topic']=inMsge\u主题,emailMesge\u主题 在互联网上也找不到类似的好例子。请建议 使用时工作正常 int kafka:入站通道适配器,但它需要轮询。(希望不进行轮询) 以下是使用的配置: <int-kafka:outbound-channel-adapter id="kafkaOutboundChannelAdapter" kafka-producer-context-ref="ka

要使用kafka:消息驱动的通道适配器使用消息

在以下通道中生成消息: 标题['topic']=inMsge\u主题,emailMesge\u主题

在互联网上也找不到类似的好例子。请建议

使用时工作正常
int kafka:入站通道适配器,但它需要轮询。(希望不进行轮询)

以下是使用的配置:

 <int-kafka:outbound-channel-adapter id="kafkaOutboundChannelAdapter" kafka-producer-context-ref="kafkaProducerContext"
                                                                 auto-startup="true" channel="inputToKafka" message-key="kafka_messageKey">
          <int:poller fixed-delay="1000" time-unit="MILLISECONDS" receive-timeout="0" task-executor="taskExecutor" /> 
   </int-kafka:outbound-channel-adapter>

   <int-kafka:producer-context id="kafkaProducerContext"
          producer-properties="producerProperties">
          <int-kafka:producer-configurations>
                <int-kafka:producer-configuration
                       broker-list="${kafka.producer.brokerList}" topic="headers['topic']" key-class-type="java.lang.String"
                       value-class-type="com.vo.MessageVO"
                       value-encoder="kafkaEncoder" key-encoder="kafkaKeyEncoder"
                       compression-type="none" />
          </int-kafka:producer-configurations>
   </int-kafka:producer-context>    
   <int:channel id="inputToKafka">
     <int:queue />
   </int:channel>

  <int:channel id="inputFromKafka">
   </int:channel>
 <bean id="kafkaConfiguration" class="org.springframework.integration.kafka.core.ZookeeperConfiguration">
   <constructor-arg ref="zookeeperConnect"/>



日志输出:

20:01:13.130[pool-5-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='inMsge_topic',id=2]@0 20:01:13.131[pool-5-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='inMsge_topic',id=4]@0 20:01:13.131[pool-5-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='inMsge_topic',id=1]@0 20:01:13.131[pool-5-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='inMsge_topic',id=0]@0 20:01:13.131[pool-5-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='inMsge_topic',id=3]@1913 20:01:13.134[pool-11-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='inMsge_topic',id=1]@0 20:01:13.134[pool-11-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='inMsge_topic',id=3]@1913 20:01:13.134[pool-11-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='inMsge_topic',id=4]@0 20:01:13.134[pool-11-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='inMsge_topic',id=2]@0 20:01:13.134[pool-11-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='inMsge_topic',id=0]@0 20:01:13.158[pool-7-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='emailMesge_topic',id=1]@0 20:01:13.158[pool-7-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='emailMesge_topic',id=3]@334 20:01:13.158[pool-7-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='emailMesge_topic',id=0]@0 20:01:13.158[pool-7-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='emailMesge_topic',id=4]@0 20:01:13.158[pool-7-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='emailMesge_topic',id=2]@0 20:01:13.164[pool-13-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='emailMesge_topic',id=1]@0 20:01:13.164[pool-13-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='emailMesge_topic',id=4]@0 20:01:13.164[pool-13-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='emailMesge_topic',id=0]@0 20:01:13.164[pool-13-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='emailMesge_topic',id=3]@334
20:01:13.164[pool-13-thread-1]调试o.s.i.kafka.core.DefaultConnection-从分区读取[topic='emailMesge_topic',id=2]@0

看看-它使用Java配置而不是XML,但同时显示出站适配器和消息驱动适配器。

你好,谢谢你的建议。。kafkaMessageDrivenChannelAdapter.setOutputChannel(received())@Bean public PollableChannel received(){return new QueueChannel();}是否要轮询消息?正在查找侦听器配置。我们也可以使用PublishSubscribeChannel/DirectChannel等。是吗?True。你可以。“kafkaMessageDrivenChannelAdapter.setOutputChannel(received());”表示从卡夫卡主题检索后将发送消息的位置。Hi@Artem感谢您的建议。尝试上面提到的Java配置示例/链接,在这里得到错误提示。(). 请提出建议。看起来您应该开始一个新问题,并就此事分享您的web应用程序配置。您可以仅从单独的上下文中使用
消费者
,该上下文不是由根webapp上下文启动的。
 <bean id="connectionFactory" class="org.springframework.integration.kafka.core.DefaultConnectionFactory">
    <constructor-arg ref="kafkaConfiguration"/>
      <int-kafka:message-driven-channel-adapter
        id="adapter"
        channel="inputFromKafka"
        connection-factory="connectionFactory"
        key-decoder="kafkaKeyDecoder"
        payload-decoder="kafkaDecoder"          
        max-fetch="100"
        topics="inMsge_topic"/>

        <int-kafka:message-driven-channel-adapter
        id="adapter1"
        channel="inputFromKafka"
        connection-factory="connectionFactory"
        key-decoder="kafkaKeyDecoder"
        payload-decoder="kafkaDecoder"          
        max-fetch="100"
        topics="emailMesge_topic"/>


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