org.springframework.kafka.support.ProducerListener Java Examples

The following examples show how to use org.springframework.kafka.support.ProducerListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NotificationEventListenerKafkaIntegrationTest.java    From stream-registry with Apache License 2.0 5 votes vote down vote up
public KafkaTemplate<SpecificRecord, SpecificRecord> kafkaTemplate() {
  KafkaTemplate<SpecificRecord, SpecificRecord> template = new KafkaTemplate<>(producerFactory());

  template.setProducerListener(new ProducerListener<>() {
    @Override
    public void onSuccess(ProducerRecord<SpecificRecord, SpecificRecord> producerRecord, RecordMetadata recordMetadata) {
      log.info("Produced record {}", producerRecord);
      producedEvents.put((AvroKey) producerRecord.key(), (AvroEvent) producerRecord.value());
      producedHeaders.put((AvroKey) producerRecord.key(), producerRecord.headers());
    }
  });

  return template;
}
 
Example #2
Source File: ReplyConfiguration.java    From faster-framework-project with Apache License 2.0 5 votes vote down vote up
public ReplyConfiguration(KafkaProperties properties,
                          org.springframework.boot.autoconfigure.kafka.KafkaProperties kafkaProperties,
                          ObjectProvider<RecordMessageConverter> messageConverter,
                          ConsumerFactory<Object, Object> consumerFactory,
                          ProducerFactory<Object, Object> producerFactory,
                          ProducerListener<Object, Object> producerListener) {
    this.kafkaProperties = kafkaProperties;
    this.properties = properties;
    this.messageConverter = messageConverter.getIfUnique();
    this.consumerFactory = consumerFactory;
    this.producerFactory = producerFactory;
    this.producerListener = producerListener;
}
 
Example #3
Source File: KafkaBinderConfigurationTest.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
@Test
public void testKafkaBinderProducerListener() {
	assertThat(this.kafkaMessageChannelBinder).isNotNull();
	Field producerListenerField = ReflectionUtils.findField(
			KafkaMessageChannelBinder.class, "producerListener",
			ProducerListener.class);
	ReflectionUtils.makeAccessible(producerListenerField);
	ProducerListener producerListener = (ProducerListener) ReflectionUtils
			.getField(producerListenerField, this.kafkaMessageChannelBinder);
	assertThat(producerListener).isNotNull();
}
 
Example #4
Source File: KafkaTestBinder.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
KafkaTestBinder(KafkaBinderConfigurationProperties binderConfiguration,
		KafkaTopicProvisioner kafkaTopicProvisioner, DlqPartitionFunction dlqPartitionFunction) {

	try {
		KafkaMessageChannelBinder binder = new KafkaMessageChannelBinder(
				binderConfiguration, kafkaTopicProvisioner, null, null, null, dlqPartitionFunction) {

			/*
			 * Some tests use multiple instance indexes for the same topic; we need to
			 * make the error infrastructure beans unique.
			 */
			@Override
			protected String errorsBaseName(ConsumerDestination destination,
					String group,
					ExtendedConsumerProperties<KafkaConsumerProperties> consumerProperties) {
				return super.errorsBaseName(destination, group, consumerProperties)
						+ "-" + consumerProperties.getInstanceIndex();
			}

		};

		ProducerListener producerListener = new LoggingProducerListener();
		binder.setProducerListener(producerListener);
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
				Config.class);
		setApplicationContext(context);
		binder.setApplicationContext(context);
		binder.afterPropertiesSet();
		this.setPollableConsumerBinder(binder);
	}
	catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example #5
Source File: KafkaMessageChannelBinder.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 4 votes vote down vote up
public void setProducerListener(ProducerListener<byte[], byte[]> producerListener) {
	this.producerListener = producerListener;
}
 
Example #6
Source File: KafkaBinderConfiguration.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
@Bean
@ConditionalOnMissingBean(ProducerListener.class)
ProducerListener producerListener() {
	return new LoggingProducerListener();
}