1
1
package com .baeldung .spring .kafka ;
2
2
3
- import java .util .HashMap ;
4
- import java .util .Map ;
5
-
6
3
import org .apache .kafka .clients .producer .ProducerConfig ;
7
4
import org .apache .kafka .common .serialization .StringSerializer ;
8
5
import org .springframework .beans .factory .annotation .Value ;
13
10
import org .springframework .kafka .core .ProducerFactory ;
14
11
import org .springframework .kafka .support .serializer .JsonSerializer ;
15
12
13
+ import java .util .HashMap ;
14
+ import java .util .Map ;
15
+
16
16
@ Configuration
17
17
public class KafkaProducerConfig {
18
18
@@ -21,30 +21,30 @@ public class KafkaProducerConfig {
21
21
22
22
@ Bean
23
23
public ProducerFactory <String , String > producerFactory () {
24
- Map <String , Object > configProps = new HashMap <String , Object >();
24
+ Map <String , Object > configProps = new HashMap <>();
25
25
configProps .put (ProducerConfig .BOOTSTRAP_SERVERS_CONFIG , bootstrapAddress );
26
26
configProps .put (ProducerConfig .KEY_SERIALIZER_CLASS_CONFIG , StringSerializer .class );
27
27
configProps .put (ProducerConfig .VALUE_SERIALIZER_CLASS_CONFIG , StringSerializer .class );
28
- return new DefaultKafkaProducerFactory <String , String >(configProps );
28
+ return new DefaultKafkaProducerFactory <>(configProps );
29
29
}
30
30
31
31
@ Bean
32
32
public KafkaTemplate <String , String > kafkaTemplate () {
33
- return new KafkaTemplate <String , String >(producerFactory ());
33
+ return new KafkaTemplate <>(producerFactory ());
34
34
}
35
35
36
36
@ Bean
37
37
public ProducerFactory <String , Greeting > greetingProducerFactory () {
38
- Map <String , Object > configProps = new HashMap <String , Object >();
38
+ Map <String , Object > configProps = new HashMap <>();
39
39
configProps .put (ProducerConfig .BOOTSTRAP_SERVERS_CONFIG , bootstrapAddress );
40
40
configProps .put (ProducerConfig .KEY_SERIALIZER_CLASS_CONFIG , StringSerializer .class );
41
41
configProps .put (ProducerConfig .VALUE_SERIALIZER_CLASS_CONFIG , JsonSerializer .class );
42
- return new DefaultKafkaProducerFactory <String , Greeting >(configProps );
42
+ return new DefaultKafkaProducerFactory <>(configProps );
43
43
}
44
44
45
45
@ Bean
46
46
public KafkaTemplate <String , Greeting > greetingKafkaTemplate () {
47
- return new KafkaTemplate <String , Greeting >(greetingProducerFactory ());
47
+ return new KafkaTemplate <>(greetingProducerFactory ());
48
48
}
49
49
50
50
}
0 commit comments