Skip to content

Commit 9659791

Browse files
authored
[JAVA-47896] Moved code from spring-kafka to spring-kafka-2 (#18658)
1 parent 5daaf34 commit 9659791

File tree

17 files changed

+38
-35
lines changed

17 files changed

+38
-35
lines changed

spring-kafka/src/main/java/com/baeldung/partitioningstrategy/CustomPartitioner.java renamed to spring-kafka-2/src/main/java/com/baeldung/spring/kafka/partitioningstrategy/CustomPartitioner.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package com.baeldung.partitioningstrategy;
1+
package com.baeldung.spring.kafka.partitioningstrategy;
2+
3+
import java.util.Map;
24

35
import org.apache.kafka.clients.producer.Partitioner;
46
import org.apache.kafka.common.Cluster;
57

6-
import java.util.Map;
7-
88
public class CustomPartitioner implements Partitioner {
99
private static final int PREMIUM_PARTITION = 0;
1010
private static final int NORMAL_PARTITION = 1;

spring-kafka/src/main/java/com/baeldung/partitioningstrategy/KafkaApplication.java renamed to spring-kafka-2/src/main/java/com/baeldung/spring/kafka/partitioningstrategy/KafkaApplication.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
package com.baeldung.partitioningstrategy;
1+
package com.baeldung.spring.kafka.partitioningstrategy;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
25

36
import org.apache.kafka.clients.consumer.ConsumerConfig;
47
import org.apache.kafka.clients.consumer.KafkaConsumer;
@@ -12,9 +15,6 @@
1215
import org.springframework.kafka.core.KafkaTemplate;
1316
import org.springframework.kafka.core.ProducerFactory;
1417

15-
import java.util.HashMap;
16-
import java.util.Map;
17-
1818
@SpringBootApplication
1919
public class KafkaApplication {
2020

@@ -26,7 +26,7 @@ public KafkaTemplate<String, String> kafkaTemplate() {
2626
@Bean
2727
public ProducerFactory<String, String> producerFactory() {
2828
Map<String, Object> configProps = new HashMap<>();
29-
configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
29+
configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9095");
3030
configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
3131
configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
3232
return new DefaultKafkaProducerFactory<>(configProps);
@@ -35,7 +35,7 @@ public ProducerFactory<String, String> producerFactory() {
3535
@Bean
3636
public KafkaConsumer<String, String> kafkaConsumer() {
3737
Map<String, Object> configProps = new HashMap<>();
38-
configProps.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
38+
configProps.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9095");
3939
configProps.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
4040
configProps.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
4141
configProps.put(ConsumerConfig.GROUP_ID_CONFIG, "test-group"); // Set a unique group ID

spring-kafka/src/main/java/com/baeldung/partitioningstrategy/KafkaMessageConsumer.java renamed to spring-kafka-2/src/main/java/com/baeldung/spring/kafka/partitioningstrategy/KafkaMessageConsumer.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1-
package com.baeldung.partitioningstrategy;
1+
package com.baeldung.spring.kafka.partitioningstrategy;
2+
3+
import java.util.List;
4+
import java.util.concurrent.CopyOnWriteArrayList;
25

3-
import jakarta.annotation.Nullable;
46
import org.springframework.kafka.annotation.KafkaListener;
57
import org.springframework.kafka.support.KafkaHeaders;
68
import org.springframework.messaging.handler.annotation.Header;
79
import org.springframework.messaging.handler.annotation.Payload;
810
import org.springframework.stereotype.Service;
911

10-
import java.util.List;
11-
import java.util.concurrent.CopyOnWriteArrayList;
12+
13+
import jakarta.annotation.Nullable;
1214

1315
@Service
1416
public class KafkaMessageConsumer {

spring-kafka/src/main/java/com/baeldung/partitioningstrategy/ReceivedMessage.java renamed to spring-kafka-2/src/main/java/com/baeldung/spring/kafka/partitioningstrategy/ReceivedMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.partitioningstrategy;
1+
package com.baeldung.spring.kafka.partitioningstrategy;
22

33
public class ReceivedMessage {
44
private final String key;

spring-kafka/src/main/java/com/baeldung/sasl/KafkaConsumer.java renamed to spring-kafka-2/src/main/java/com/baeldung/spring/kafka/sasl/KafkaConsumer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
package com.baeldung.sasl;
1+
package com.baeldung.spring.kafka.sasl;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
25

3-
import lombok.extern.slf4j.Slf4j;
46
import org.apache.kafka.clients.consumer.ConsumerRecord;
57
import org.springframework.kafka.annotation.KafkaListener;
68
import org.springframework.stereotype.Component;
79

8-
import java.util.ArrayList;
9-
import java.util.List;
10+
import lombok.extern.slf4j.Slf4j;
1011

1112
@Component
1213
@Slf4j

spring-kafka/src/main/java/com/baeldung/sasl/KafkaSaslApplication.java renamed to spring-kafka-2/src/main/java/com/baeldung/spring/kafka/sasl/KafkaSaslApplication.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.sasl;
1+
package com.baeldung.spring.kafka.sasl;
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;

spring-kafka-2/src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
spring.kafka.bootstrap-servers=localhost:9092,localhost:9093,localhost:9094
1+
spring.kafka.bootstrap-servers=localhost:9092,localhost:9093,localhost:9094, localhost:9095
22
message.topic.name=baeldung
33
long.message.topic.name=longMessage
44
greeting.topic.name=greeting

spring-kafka/src/test/java/com/baeldung/partitioningstrategy/KafkaApplicationIntegrationTest.java renamed to spring-kafka-2/src/test/java/com/baeldung/spring/kafka/partitioningstrategy/KafkaApplicationIntegrationTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
package com.baeldung.partitioningstrategy;
1+
package com.baeldung.spring.kafka.partitioningstrategy;
2+
3+
import static java.util.concurrent.TimeUnit.SECONDS;
4+
import static org.awaitility.Awaitility.await;
5+
import static org.junit.Assert.assertEquals;
6+
7+
import java.time.Duration;
8+
import java.util.Collections;
9+
import java.util.List;
10+
import java.util.Map;
11+
import java.util.Set;
12+
import java.util.stream.Collectors;
213

314
import org.apache.kafka.clients.consumer.Consumer;
415
import org.apache.kafka.clients.consumer.ConsumerRecord;
@@ -16,19 +27,8 @@
1627
import org.springframework.kafka.test.context.EmbeddedKafka;
1728
import org.springframework.kafka.test.utils.KafkaTestUtils;
1829

19-
import java.time.Duration;
20-
import java.util.Collections;
21-
import java.util.List;
22-
import java.util.Map;
23-
import java.util.Set;
24-
import java.util.stream.Collectors;
25-
26-
import static java.util.concurrent.TimeUnit.SECONDS;
27-
import static org.awaitility.Awaitility.await;
28-
import static org.junit.Assert.assertEquals;
29-
3030
@SpringBootTest
31-
@EmbeddedKafka(partitions = 3, brokerProperties = { "listeners=PLAINTEXT://localhost:9092" }, kraft = false)
31+
@EmbeddedKafka(partitions = 3, brokerProperties = { "listeners=PLAINTEXT://localhost:9095" }, kraft = false)
3232
public class KafkaApplicationIntegrationTest {
3333

3434
@Autowired

spring-kafka/src/test/java/com/baeldung/sasl/SprintContextTest.java renamed to spring-kafka-2/src/test/java/com/baeldung/spring/kafka/sasl/SprintContextTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.sasl;
1+
package com.baeldung.spring.kafka.sasl;
22

33
import org.junit.jupiter.api.Test;
44
import org.junit.jupiter.api.extension.ExtendWith;
@@ -7,7 +7,7 @@
77

88
@ExtendWith(SpringExtension.class)
99
@SpringBootTest(classes = KafkaSaslApplication.class)
10-
class SpringContextTest {
10+
class SprintContextTest {
1111

1212
@Test
1313
void whenSpringContextIsBootstrapped_thenNoExceptions() {

0 commit comments

Comments
 (0)