diff --git a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/ProducerConfiguration.java b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/ProducerConfiguration.java index 0482039bd0..a6a9e53e78 100644 --- a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/ProducerConfiguration.java +++ b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/ProducerConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2015 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. @@ -18,8 +18,6 @@ package org.springframework.integration.kafka.support; import java.util.concurrent.Future; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.kafka.clients.producer.Producer; import org.apache.kafka.clients.producer.ProducerRecord; import org.apache.kafka.clients.producer.RecordMetadata; @@ -36,6 +34,7 @@ import org.springframework.util.StringUtils; * @author Ilayaperumal Gopinathan * @author Gary Russell * @author Marius Bogoevici + * @author Artem Bilan * @since 0.5 */ public class ProducerConfiguration { @@ -53,7 +52,7 @@ public class ProducerConfiguration { this.producer = producer; GenericConversionService genericConversionService = new GenericConversionService(); genericConversionService.addConverter(Object.class, byte[].class, new SerializingConverter()); - conversionService = genericConversionService; + this.conversionService = genericConversionService; } public void setConversionService(ConversionService conversionService) { @@ -80,12 +79,13 @@ public class ProducerConfiguration { return this.producer.send(new ProducerRecord<>(targetTopic, partition, messageKey, messagePayload)); } - public Future convertAndSend(String topic, Integer partition, Object messageKey, Object messagePayload) { - return this.send(topic, partition, convertKeyIfNecessary(messageKey), convertPayloadIfNecessary(messagePayload)); + public Future convertAndSend(String topic, Integer partition, Object messageKey, + Object messagePayload) { + return send(topic, partition, convertKeyIfNecessary(messageKey), convertPayloadIfNecessary(messagePayload)); } public Future convertAndSend(String topic, Object messageKey, Object messagePayload) { - return this.send(topic, convertKeyIfNecessary(messageKey), convertPayloadIfNecessary(messagePayload)); + return send(topic, convertKeyIfNecessary(messageKey), convertPayloadIfNecessary(messagePayload)); } private K convertKeyIfNecessary(Object messageKey) { @@ -94,8 +94,7 @@ public class ProducerConfiguration { messageKey.getClass())) { return getProducerMetadata().getKeyClassType().cast(messageKey); } - return conversionService.convert(messageKey, - producerMetadata.getKeyClassType()); + return this.conversionService.convert(messageKey, this.producerMetadata.getKeyClassType()); } else { return null; @@ -108,31 +107,24 @@ public class ProducerConfiguration { messagePayload.getClass())) { return getProducerMetadata().getValueClassType().cast(messagePayload); } - return conversionService.convert(messagePayload, - producerMetadata.getValueClassType()); + return this.conversionService.convert(messagePayload, this.producerMetadata.getValueClassType()); } else { return null; } } - @Override - public boolean equals(final Object obj) { - return EqualsBuilder.reflectionEquals(this, obj); - } - - @Override - public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); - } - - @Override - public String toString() { - return "ProducerConfiguration [producerMetadata=" + this.producerMetadata + "]"; - } - public void stop() { this.producer.close(); } + @Override + public String toString() { + return "ProducerConfiguration{" + + "producer=" + this.producer + + ", producerMetadata=" + this.producerMetadata + + ", conversionService=" + this.conversionService + + '}'; + } + } diff --git a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/ProducerMetadata.java b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/ProducerMetadata.java index 85a8dfd622..1d3e494f81 100644 --- a/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/ProducerMetadata.java +++ b/spring-integration-kafka/src/main/java/org/springframework/integration/kafka/support/ProducerMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -13,20 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.kafka.support; -import kafka.producer.Partitioner; -import org.apache.commons.lang.builder.EqualsBuilder; -import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.kafka.common.serialization.Serializer; import org.springframework.util.Assert; +import kafka.producer.Partitioner; + /** * * @author Soby Chacko * @author Rajasekar Elango * @author Marius Bogoevici + * @author Artem Bilan * * @since 0.5 */ @@ -48,7 +49,8 @@ public class ProducerMetadata { private int batchBytes = 16384; - public ProducerMetadata(final String topic, Class keyClassType, Class valueClassType, Serializer keySerializer, Serializer valueSerializer) { + public ProducerMetadata(final String topic, Class keyClassType, Class valueClassType, + Serializer keySerializer, Serializer valueSerializer) { Assert.notNull(topic, "Topic cannot be null"); Assert.notNull(keyClassType, "Key class type serializer cannot be null"); Assert.notNull(valueClassType, "Value class type cannot be null"); @@ -107,25 +109,18 @@ public class ProducerMetadata { return valueClassType; } - @Override - public boolean equals(final Object obj){ - return EqualsBuilder.reflectionEquals(this, obj); - } - - @Override - public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); - } - @Override public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("ProducerMetadata [keyEncoder=").append(keySerializer) - .append(", valueEncoder=").append(valueSerializer) - .append(", topic=").append(topic) - .append(", compressionType=").append(compressionType) - .append("batchBytes").append(batchBytes).append("]"); - return builder.toString(); + return "ProducerMetadata{" + + "keyClassType=" + this.keyClassType + + ", valueClassType=" + this.valueClassType + + ", keySerializer=" + this.keySerializer + + ", valueSerializer=" + this.valueSerializer + + ", topic='" + this.topic + '\'' + + ", partitioner=" + this.partitioner + + ", compressionType=" + this.compressionType + + ", batchBytes=" + this.batchBytes + + '}'; } public enum CompressionType { @@ -133,4 +128,5 @@ public class ProducerMetadata { gzip, snappy } + }