发件人结果通道

从 4.0.3 版开始,您可以配置resultMetadataChannel接收SenderResult<?>s 来确定发送的成功/失败。spring-doc.cadn.net.cn

SenderResult包含correlationMetadata允许您将结果与发送相关联;它还包含RecordMetadata,表示TopicPartition以及已发送记录的偏移量。spring-doc.cadn.net.cn

resultMetadataChannel 必须FluxMessageChannel实例。spring-doc.cadn.net.cn

下面是如何使用此功能的示例,相关元数据类型为Integer:spring-doc.cadn.net.cn

@Bean
FluxMessageChannel sendResults() {
    return new FluxMessageChannel();
}

@ServiceActivator(inputChannel = "sendResults")
void handleResults(SenderResult<Integer> result) {
    if (result.exception() != null) {
        failureFor(result);
    }
    else {
        successFor(result);
    }
}

要在输出记录上设置相关元数据,请将CORRELATION_ID页眉:spring-doc.cadn.net.cn

streamBridge.send("words1", MessageBuilder.withPayload("foobar")
        .setCorrelationId(42)
        .build());

将该功能与Function,则函数输出类型必须是Message<?>将相关 ID 标头设置为所需值。spring-doc.cadn.net.cn

元数据应是唯一的,至少在发送期间是唯一的。spring-doc.cadn.net.cn