Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProducerListener: add CompositeProducerListener or list of ProducerListener #691

Closed
mayras opened this issue May 24, 2018 · 2 comments
Closed

Comments

@mayras
Copy link

mayras commented May 24, 2018

Typical situation when there is the need of list of listeners, but there can be set up one ProducerListener for KafkaTemplate only. Pls add CompositeProducerListener with list of inner listeners or
enhance KafkaTemplate to addProducerListener method.

@artembilan
Copy link
Member

I think this is fully valid request and CompositeProducerListener sounds good to me.

I guess you can simply implement one for your project yourself and when you're done, feel free to contribute it back to the Framework!

@mayras
Copy link
Author

mayras commented May 25, 2018

public class CompositeProducerListener<K, V> implements ProducerListener<K, V> {

    private List<ProducerListener<K,V>> producerListeners = newArrayList();
    private boolean interestedInSuccess;

    public CompositeProducerListener(List<ProducerListener<K,V>> producerListeners, boolean interestedInSuccess) {
        this.producerListeners = producerListeners;
        this.interestedInSuccess = interestedInSuccess;
    }

    @Override
    public void onSuccess(String topic, Integer partition, K key, V value, RecordMetadata recordMetadata) {
        producerListeners.forEach(c -> c.onSuccess(topic, partition, key, value, recordMetadata));
    }

    @Override
    public void onError(String topic, Integer partition, K key, V value, Exception exception) {
        producerListeners.forEach(c -> c.onError(topic, partition, key, value, exception));
    }

    @Override
    public boolean isInterestedInSuccess() {
        return interestedInSuccess;
    }
}

garyrussell added a commit to garyrussell/spring-kafka that referenced this issue May 28, 2018
garyrussell added a commit to garyrussell/spring-kafka that referenced this issue May 28, 2018
garyrussell added a commit to garyrussell/spring-kafka that referenced this issue May 28, 2018
artembilan pushed a commit that referenced this issue May 29, 2018
Fixes #691

**cherry-pick to 2.1.x**

* Polishing - PR Comments

Improve test.
artembilan pushed a commit that referenced this issue May 29, 2018
Fixes #691

**cherry-pick to 2.1.x**

* Polishing - PR Comments

Improve test.

(cherry picked from commit 2355bda)
denis554 added a commit to denis554/spring-kafka that referenced this issue Mar 27, 2019
Fixes spring-projects/spring-kafka#691

**cherry-pick to 2.1.x**

* Polishing - PR Comments

Improve test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants