Skip to content

Commit efc2043

Browse files
authored
KafkaProducerConfig refactor (eugenp#1488)
1 parent b6e271f commit efc2043

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
<module>spring-jms</module>
145145
<module>spring-jooq</module>
146146
<module>spring-jpa</module>
147+
<module>spring-kafka</module>
147148
<module>spring-katharsis</module>
148149
<module>spring-ldap</module>
149150
<module>spring-mockito</module>
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package com.baeldung.spring.kafka;
22

3-
import java.util.HashMap;
4-
import java.util.Map;
5-
63
import org.apache.kafka.clients.producer.ProducerConfig;
74
import org.apache.kafka.common.serialization.StringSerializer;
85
import org.springframework.beans.factory.annotation.Value;
@@ -13,6 +10,9 @@
1310
import org.springframework.kafka.core.ProducerFactory;
1411
import org.springframework.kafka.support.serializer.JsonSerializer;
1512

13+
import java.util.HashMap;
14+
import java.util.Map;
15+
1616
@Configuration
1717
public class KafkaProducerConfig {
1818

@@ -21,30 +21,30 @@ public class KafkaProducerConfig {
2121

2222
@Bean
2323
public ProducerFactory<String, String> producerFactory() {
24-
Map<String, Object> configProps = new HashMap<String, Object>();
24+
Map<String, Object> configProps = new HashMap<>();
2525
configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
2626
configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
2727
configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
28-
return new DefaultKafkaProducerFactory<String, String>(configProps);
28+
return new DefaultKafkaProducerFactory<>(configProps);
2929
}
3030

3131
@Bean
3232
public KafkaTemplate<String, String> kafkaTemplate() {
33-
return new KafkaTemplate<String, String>(producerFactory());
33+
return new KafkaTemplate<>(producerFactory());
3434
}
3535

3636
@Bean
3737
public ProducerFactory<String, Greeting> greetingProducerFactory() {
38-
Map<String, Object> configProps = new HashMap<String, Object>();
38+
Map<String, Object> configProps = new HashMap<>();
3939
configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
4040
configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
4141
configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
42-
return new DefaultKafkaProducerFactory<String, Greeting>(configProps);
42+
return new DefaultKafkaProducerFactory<>(configProps);
4343
}
4444

4545
@Bean
4646
public KafkaTemplate<String, Greeting> greetingKafkaTemplate() {
47-
return new KafkaTemplate<String, Greeting>(greetingProducerFactory());
47+
return new KafkaTemplate<>(greetingProducerFactory());
4848
}
4949

5050
}

0 commit comments

Comments
 (0)