It is not clear how to handle onsuccess and onerror results when using Kafka
See original GitHub issueThe framework offers MessageChannel as a way to send the messages asynchronously/synchronously:
@Autowired
private Source source;
public void sayHello(String name) {
source.output().send(MessageBuilder.withPayload(body).build());
}
However the MessageChannel API doesn’t allow the use of any type of callback to handle onsuccess and onerror results.
When a delivery fails I observe that there is a automatically registered LoggingProducerListener that prints the error:
public interface ProducerListener<K, V> {
void onSuccess(String topic, Integer partition, K key, V value, RecordMetadata recordMetadata);
void onError(String topic, Integer partition, K key, V value, Exception exception);
boolean isInterestedInSuccess();
}
It would come in handy if we could specify a callback in the send() operation.
Otherwise, how can we register a custom error handler per operation? How can we know that the operation was successful? Are we supposed to use directly the KafkaTemplate (KafkaTemplate.setProducerListener) ?
In any case it would be great if the doc were a little bit clearer in this regards.
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
It is not clear how to handle onsuccess and onerror results when ...
The framework offers MessageChannel as a way to send the messages asynchronously/synchronously: @Autowired private Source source; ...
Read more >Error Handling Patterns in Kafka - Confluent
This is a common scenario where events that cannot be processed by the application are routed to an error topic while the main...
Read more >KafkaTemplate producer send callback onFailure not called ...
So, you need to use try..catch around that kafkaTemplate.send() to handle that kind of Error while fetching metadata problems.
Read more >Error handling with reactive streams. | by Kalpa Senanayake
Here in this post we are going to discuss various error handling mechanisms offered through reactive stream fluent APIs. For this example we...
Read more >Spring for Apache Kafka
If you are not using Spring Boot, declare the spring-kafka jar as a ... be sure that enough threads are available to handle...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Since version 1.3, you can use the
error-channel-enabledproducer property.Example:
and
(Use a service activator subscribed to the error channel).
and…
I updated the example to see how to get the results of successful sends, using a
ProducerInterceptor: