这是有关使用spring-batch和spring-kafka的其他几个SO问题的后续措施。
意图:
目的是建立这样的呼叫链(简化视图):
Master调用从属步骤:
<master job> -> partitioner (MessageChannelPartitionHandler) +aggregator -> messagingTemplate -> outbound-requests (Channel) -> request-outbound-staging (KafkaProducerMessageHandler) -> kafka
Kafka侦听器响应消息并触发奴隶工步骤
kafka -> inbound-request-listener (MessageDrivenChannelAdapter) -> inbound-requests (channel) -> worker-container (KafkaMessageListenerContainer) -> stepExecutionRequestHandler <slave step>
春季批处理答复返回给Kafka
stepExecutionRequestHandler <slave step> -> stepMessagingTemplate -> outbound-replies (Channel) -> reply-outbound-staging (KafkaProducerMessageHandler) -> kafka
Kafka侦听器将回复返回给聚合器和分区器
kafka -> inbound-replies (MessageDrivenChannelAdapter) -> partitioner (MessageChannelPartitionHandler) +aggregator -> <master job>
历史记录:
最初确定了与kafka的弹簧集成配置后,该进程从属端的spring-batch组件没有找到启动侦听器的步骤。
我们重构了驱动它们的spring-batch组件和spring-integration,最终将它们和侦听器组件移出了Java DSL并移入了从属步骤XML。
当前状态:
重构后,kafka侦听器似乎不再响应。唯一的症状是从属进程没有响应,并且聚合器超时。
Java DSL配置:
@Configuration
@Order(6)
@EnableIntegration
@EnableKafka
@IntegrationComponentScan
public class QueueingConfig {
private static final int MXMODULE = 400;
private static final String JOB_CONTROL_TOPIC = "job.control";
private static final String STEP_EXECUTION_TOPICS = "job.step";
private static final String STEP_REPLY_TOPICS = "job.step.reply";
XML配置片段:
<bean id="worker-container" class="org.springframework.kafka.listener.KafkaMessageListenerContainer">
<constructor-arg>
<bean class="org.springframework.kafka.core.DefaultKafkaConsumerFactory">
<constructor-arg>
<map>
<entry key="bootstrap.servers" value="192.168.2.127:9092" /> <!-- needs to come from factory bean -->
<entry key="key.deserializer" value="org.apache.kafka.common.serialization.IntegerDeserializer"/>
<entry key="value.deserializer" value="org.springframework.kafka.support.serializer.JsonDeserializer"/>
<entry key="group.id" value="batch"/>
<entry key="spring.json.trusted.packages" value="com.mypackage,org.springframework.batch.integration.partition"/>
<entry key="max.poll.records" value="10"/>
</map>
</constructor-arg>
</bean>
</constructor-arg>
<constructor-arg>
<bean class="org.springframework.kafka.listener.ContainerProperties">
<constructor-arg name="topics" value="job.step" />
</bean>
</constructor-arg>
</bean>
<int-kafka:message-driven-channel-adapter
id="inboundKafkaRequests"
send-timeout="5000"
mode="record"
channel="inbound-requests"
auto-startup="true"
listener-container="worker-container"
/>
先前研究:
Spring Integration Kafka Consumer Listener not Receiving messages
How do I convert this spring-integration configuration from XML to Java?
编辑:更新
在Linux补丁程序更新期间,kafka配置文件被默认文件覆盖。我恢复了正确的配置,kafka恢复了操作。
在编写此问题的练习中,我将许多弹簧接线形式化了。形式化过程有助于识别未集成组件的一些问题。