希望使用kafka:message-driven-channel-adapter.
在以下频道中生成消息:headers['topic']=inmsge\u topic,emailmesge\u topic
在网上也找不到类似的好例子。请建议。
使用时工作正常
内景-kafka:inbound-channel-adapter but 它需要轮询
以下是使用的配置:
<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"/>
<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" />
日志输出:
20:01:13.130[pool-5-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='inmsge\u topic',id=2]@0 20:01:13.131[pool-5-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='inmsge\u topic',id=4]@0 20:01:13.131[pool-5-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='inmsge\u topic',id=1]@0 20:01:13.131[pool-5-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='inmsge\u topic',id=0]@0 20:01:13.131[pool-5-thread-1]debug o.s.i.kafka.core.defaultconnection-从分区读取[topic='inmsge\u topic',id=3]@1913 20:01:13.134[pool-11-thread-1]debug o.s.i.kafka.core.defaultconnection-从分区读取[topic='inmsge\u topic',id=1]@0 20:01:13.134[pool-11-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='inmsge\u topic',id=3]@1913 20:01:13.134[pool-11-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='inmsge\u topic',id=4]@0 20:01:13.134[pool-11-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='inmsge\u topic',id=2]@0 20:01:13.134[pool-11-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='inmsge\u topic',id=0]@0 20:01:13.158[pool-7-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='emailmesge\u topic',id=1]@0 20:01:13.158[pool-7-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='emailmesge\u topic',id=3]@334 20:01:13.158[pool-7-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='emailmesge\u topic',id=0]@0 20:01:13.158[pool-7-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='emailmesge\u topic',id=4]@0 20:01:13.158[pool-7-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='emailmesge\u topic',id=2]@0 20:01:13.164[pool-13-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='emailmesge\u topic',id=1]@0 20:01:13.164[pool-13-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='emailmesge\u topic',id=4]@0 20:01:13.164[pool-13-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='emailmesge\u topic',id=0]@0 20:01:13.164[pool-13-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='emailmesge\u topic',id=3]@334 20:01:13.164[pool-13-thread-1]调试o.s.i.kafka.core.defaultconnection-从分区读取[topic='emailmesge\u topic',id=2]@0
1条答案
按热度按时间wlzqhblo1#
看看SpringIntegrationKafka示例—它使用java配置而不是xml,但它同时显示出站适配器和消息驱动适配器。