projects
/
demos
/
kafka
/
demos-kafka-payment-system-transfer
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
90762b3
)
Properties are only accessible via getters
author
Kai Moritz
<kai@juplo.de>
Wed, 23 Jun 2021 20:10:19 +0000
(22:10 +0200)
committer
Kai Moritz
<kai@juplo.de>
Wed, 23 Jun 2021 20:20:09 +0000
(22:20 +0200)
src/main/java/de/juplo/kafka/payment/transfer/TransferServiceApplication.java
patch
|
blob
|
history
src/main/java/de/juplo/kafka/payment/transfer/TransferServiceProperties.java
patch
|
blob
|
history
diff --git
a/src/main/java/de/juplo/kafka/payment/transfer/TransferServiceApplication.java
b/src/main/java/de/juplo/kafka/payment/transfer/TransferServiceApplication.java
index
eab6abf
..
53ff0f4
100644
(file)
--- a/
src/main/java/de/juplo/kafka/payment/transfer/TransferServiceApplication.java
+++ b/
src/main/java/de/juplo/kafka/payment/transfer/TransferServiceApplication.java
@@
-20,6
+20,7
@@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
+import org.springframework.util.Assert;
import java.util.Optional;
import java.util.Properties;
import java.util.Optional;
import java.util.Properties;
@@
-33,8
+34,11
@@
public class TransferServiceApplication
@Bean(destroyMethod = "close")
KafkaProducer<String, String> producer(TransferServiceProperties properties)
{
@Bean(destroyMethod = "close")
KafkaProducer<String, String> producer(TransferServiceProperties properties)
{
+ Assert.hasText(properties.getBootstrapServers(), "juplo.transfer.bootstrap-servers must be set");
+ Assert.hasText(properties.getTopic(), "juplo.transfer.topic must be set");
+
Properties props = new Properties();
Properties props = new Properties();
- props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, properties.
bootstrapServers
);
+ props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, properties.
getBootstrapServers()
);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class);
@@
-44,9
+48,12
@@
public class TransferServiceApplication
@Bean
KafkaConsumer<String, String> consumer(TransferServiceProperties properties)
{
@Bean
KafkaConsumer<String, String> consumer(TransferServiceProperties properties)
{
+ Assert.hasText(properties.getBootstrapServers(), "juplo.transfer.bootstrap-servers must be set");
+ Assert.hasText(properties.getGroupId(), "juplo.transfer.group-id must be set");
+
Properties props = new Properties();
Properties props = new Properties();
- props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, properties.
bootstrapServers
);
- props.put(ConsumerConfig.GROUP_ID_CONFIG, properties.g
roupId
);
+ props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, properties.
getBootstrapServers()
);
+ props.put(ConsumerConfig.GROUP_ID_CONFIG, properties.g
etGroupId()
);
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
@@
-65,7
+72,7
@@
public class TransferServiceApplication
{
return
new TransferConsumer(
{
return
new TransferConsumer(
- properties.
topic
,
+ properties.
getTopic()
,
consumer,
mapper,
new TransferConsumer.ConsumerUseCases() {
consumer,
mapper,
new TransferConsumer.ConsumerUseCases() {
@@
-114,7
+121,7
@@
public class TransferServiceApplication
ObjectMapper mapper,
TransferServiceProperties properties)
{
ObjectMapper mapper,
TransferServiceProperties properties)
{
- return new KafkaMessagingService(producer, mapper, properties.
topic
);
+ return new KafkaMessagingService(producer, mapper, properties.
getTopic()
);
}
@Bean
}
@Bean
diff --git
a/src/main/java/de/juplo/kafka/payment/transfer/TransferServiceProperties.java
b/src/main/java/de/juplo/kafka/payment/transfer/TransferServiceProperties.java
index
79473f8
..
c18f525
100644
(file)
--- a/
src/main/java/de/juplo/kafka/payment/transfer/TransferServiceProperties.java
+++ b/
src/main/java/de/juplo/kafka/payment/transfer/TransferServiceProperties.java
@@
-11,7
+11,7
@@
import org.springframework.boot.context.properties.ConfigurationProperties;
@Setter
public class TransferServiceProperties
{
@Setter
public class TransferServiceProperties
{
- String bootstrapServers = "localhost:9092";
- String topic = "transfers";
- String groupId = "transfers";
+
private
String bootstrapServers = "localhost:9092";
+
private
String topic = "transfers";
+
private
String groupId = "transfers";
}
}