Skip to content

Commit

Permalink
change typo for properties (use of nested class configuration)
Browse files Browse the repository at this point in the history
  • Loading branch information
monxxi committed May 18, 2020
1 parent 16435b2 commit b1d6d2e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ module.exports = class extends BaseGenerator {
'[bootstrap.servers]': localhost:9092
`;
if (this.components.includes('consumer') && this.pollingTimeout) {
kafkaProperties += `pollingTimeout: ${this.pollingTimeout}
kafkaProperties += `polling.timeout: ${this.pollingTimeout}
`;
}
let consumersCpt = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,17 @@ import java.util.Map;
@Configuration
@ConfigurationProperties(prefix = "kafka")
public class KafkaProperties {
public static final int DEFAULT_POLL_TIMEOUT = 10_000;
public static final String BOOTSTRAP_SERVER = "localhost:9092";

private Map<String, Map<String, Object>> consumer = new HashMap<>();

private Map<String, Map<String, Object>> producer = new HashMap<>();

private Integer pollingTimeout;
private Polling polling = new Polling();

@PostConstruct
public void init() {

if (pollingTimeout == null) {
pollingTimeout = DEFAULT_POLL_TIMEOUT;
}

for (String consumerKey: consumer.keySet()) {
final Map<String, Object> properties = consumer.get(consumerKey);
if (! properties.containsKey(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG)) {
Expand All @@ -61,12 +56,8 @@ public class KafkaProperties {
}
}

public Integer getPollingTimeout() {
return pollingTimeout;
}

public void setPollingTimeout(Integer pollingTimeout) {
this.pollingTimeout = pollingTimeout;
public Polling getPolling() {
return polling;
}

public Map<String, Map<String, Object>> getConsumer() {
Expand All @@ -84,4 +75,17 @@ public class KafkaProperties {
public void setProducer(Map<String, Map<String, Object>> producer) {
this.producer = producer;
}

public static class Polling {
protected static final int DEFAULT_POLL_TIMEOUT = 10_000;
private Integer timeout = DEFAULT_POLL_TIMEOUT;

public Integer getTimeout() {
return timeout;
}

public void setTimeout(Integer timeout) {
this.timeout = timeout;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class <%= entityClass %>Consumer extends GenericConsumer<<%= entityClass
private final Logger log = LoggerFactory.getLogger(<%= entityClass %>.class);

public <%= entityClass %>Consumer(@Value("${kafka.consumer.<%= camelCaseEntityClass %>.name}") final String topic, final KafkaProperties kafkaProperties) {
super(topic, kafkaProperties.getConsumer().get("<%= camelCaseEntityClass %>"), kafkaProperties.getPollingTimeout());
super(topic, kafkaProperties.getConsumer().get("<%= camelCaseEntityClass %>"), kafkaProperties.getPolling().getTimeout());
}

@Override
Expand Down

0 comments on commit b1d6d2e

Please sign in to comment.