From a98aba36c77b61aa08e6994f8714eace2b7ef80c Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 6 Jan 2016 11:01:04 -0500 Subject: [PATCH] INTEXT-216: KafkaProducerContext.beanName as null JIRA: https://jira.spring.io/browse/INTEXT-216 Having the default value for the `NamedComponent` contract (`beanName`) doesn't allow us to override (generate) the unique bean name for the component. Clean up `KafkaProducerContext.beanName` to `null` by default. **Cherry-pick to 1.3.x** --- .../kafka/support/KafkaProducerContext.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/KafkaProducerContext.java b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/KafkaProducerContext.java index f4559730ce..836ca53c63 100644 --- a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/KafkaProducerContext.java +++ b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/KafkaProducerContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,13 +23,11 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.clients.producer.RecordMetadata; import org.springframework.beans.factory.BeanNameAware; import org.springframework.context.SmartLifecycle; import org.springframework.integration.support.context.NamedComponent; -import org.springframework.messaging.Message; import org.springframework.util.StringUtils; /** @@ -49,9 +47,9 @@ public class KafkaProducerContext implements SmartLifecycle, NamedComponent, Bea private volatile Map> producerConfigurations; - private volatile ProducerConfiguration theProducerConfiguration; + private volatile ProducerConfiguration theProducerConfiguration; - private String beanName = "not_specified"; + private String beanName; private int phase = 0; @@ -187,18 +185,19 @@ public class KafkaProducerContext implements SmartLifecycle, NamedComponent, Bea } public Future send(String topic, Object messageKey, Object messagePayload) { - return this.send(topic, null, messageKey, messagePayload); + return send(topic, null, messageKey, messagePayload); } public Future send(String topic, Integer partition, Object messageKey, Object messagePayload) { - if (!running.get()) { + if (!this.running.get()) { start(); } // only try to look up for a producer configuration if the topic is passed as argument // if no topic is configured, then we'll fall back to the default if a single // producer configuration is available - ProducerConfiguration producerConfiguration = StringUtils.hasText(topic) ? getTopicConfiguration(topic) : null; + ProducerConfiguration producerConfiguration = + StringUtils.hasText(topic) ? getTopicConfiguration(topic) : null; if (producerConfiguration != null) { return producerConfiguration.convertAndSend(topic, partition, messageKey, messagePayload);