此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 spring-cloud-stream 4.1.4! |
发送方结果通道
从版本 4.0.3 开始,您可以配置resultMetadataChannel
接收SenderResult<?>
S 来确定发送的成功/失败。
这SenderResult
包含correlationMetadata
允许您将结果与发送相关联;它还包含RecordMetadata
,它表示TopicPartition
和 offset 的发送记录。
这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<?>
并将 Correlation ID 标头设置为所需的值。
元数据应该是唯一的,至少在发送期间是唯一的。