spring-cloud / spring-cloud-stream-binder-kafka

Spring Cloud Stream binders for Apache Kafka and Kafka Streams
Apache License 2.0
331 stars 301 forks source link

How to use sendSuccessChannel? #1101

Closed yangweicode closed 3 years ago

yangweicode commented 3 years ago

I saw “sendSuccessChannel” in “KafkaProducerMessageHandler”,But I didn’t find the relevant usage introduction

garyrussell commented 3 years ago

GitHub issues are not for asking questions; use stack overflow for questions.

See https://docs.spring.io/spring-cloud-stream-binder-kafka/docs/3.1.3/reference/html/spring-cloud-stream-binder-kafka.html#kafka-producer-properties

recordMetadataChannel

The bean name of a MessageChannel to which successful send results should be sent; the bean must exist in the application context. The message sent to the channel is the sent message (after conversion, if any) with an additional header KafkaHeaders.RECORD_METADATA. The header contains a RecordMetadata object provided by the Kafka client; it includes the partition and offset where the record was written in the topic.

ResultMetadata meta = sendResultMsg.getHeaders().get(KafkaHeaders.RECORD_METADATA, RecordMetadata.class)

Subscribe to that channel with a @ServiceActivator or IntegrationFlow bean.