发送方结果通道
从 4.0.3 版本开始,您可以配置 `resultMetadataChannel` 来接收 `SenderResult>`,以确定发送操作的成功/失败。
`SenderResult` 包含 `correlationMetadata`,使您能够将结果与发送操作关联起来;它还包含 `RecordMetadata`,该信息指示了发送记录的 `TopicPartition` 和偏移量。
`resultMetadataChannel` **必须** 是 `FluxMessageChannel` 实例。
以下是使用此功能的一个示例,关联元数据的类型为 `Integer`
@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` 头部
streamBridge.send("words1", MessageBuilder.withPayload("foobar")
.setCorrelationId(42)
.build());
将此功能与 `Function` 一起使用时,函数的输出类型必须是 `Message>`,并且关联 ID 头部必须设置为期望的值。
元数据应该是唯一的,至少在发送操作期间内应如此。