你的问题是你使用单向
Kafka.outboundChannelAdapter(producerFactory)
. 这只是为了“发送和忘记”。
如果您有兴趣生成一些后续进程,或者只是在需要答复HTTP请求时,您应该考虑使用:
/**
* The {@link org.springframework.integration.channel.PublishSubscribeChannel} {@link #channel}
* method specific implementation to allow the use of the 'subflow' subscriber capability.
* @param publishSubscribeChannelConfigurer the {@link Consumer} to specify
* {@link PublishSubscribeSpec} options including 'subflow' definition.
* @return the current {@link IntegrationFlowDefinition}.
*/
public B publishSubscribeChannel(Consumer<PublishSubscribeSpec> publishSubscribeChannelConfigurer) {
在流定义中,您的第一个订户实际上是
Kafka.OutboundChannelAdapter(产品工厂)
第二个可以是上面提到的
.enrichHeaders()
. 如果您再不做任何操作,最后一个将把结果发送到
replyChannel
因此,头将到达HTTP响应。
在这个发布订阅场景中,您应该记住
payload
因为第二个订户将和你试图发送给卡夫卡的一样。