Skip to content

Commit

Permalink
Merge pull request #42 from fdelbrayelle/fix/issues/22_topic_naming_c…
Browse files Browse the repository at this point in the history
…onvention

feat: set a topic naming convention

closes #22
  • Loading branch information
fdelbrayelle authored May 18, 2020
2 parents 7848fab + df97b4c commit eece891
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 15 additions & 4 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ module.exports = class extends BaseGenerator {
// read config from .yo-rc.json
this.baseName = this.jhipsterAppConfig.baseName;
this.dasherizedBaseName = _.kebabCase(this.baseName);
this.snakeCaseBaseName = _.snakeCase(this.baseName);
this.packageName = this.jhipsterAppConfig.packageName;
this.packageFolder = this.jhipsterAppConfig.packageFolder;
this.clientFramework = this.jhipsterAppConfig.clientFramework;
Expand Down Expand Up @@ -221,8 +222,8 @@ module.exports = class extends BaseGenerator {

this.entities.forEach(entity => {
this.entityClass = entity;
this.dasherizedEntityClass = _.kebabCase(entity);
this.camelCaseEntityClass = _.camelCase(entity);
this.snakeCaseEntityClass = _.snakeCase(entity);

if (this.components.includes('consumer')) {
if (consumersCpt === 0) {
Expand All @@ -231,7 +232,12 @@ module.exports = class extends BaseGenerator {

kafkaProperties += `
${this.camelCaseEntityClass}:
name: ${this.dasherizedEntityClass}-topic
# This is a template topic naming convention which can be changed.
# %3Cmessage_type%3E.%3Capplication_name%3E.%3Centity_name%3E with (all in snake_case):
# - %3Cmessage_type%3E: queuing, logging, tracking, etl/db, streaming, push, user...
# - %3Capplication_name%3E: the application base name
# - %3Centity_name%3E: the entity name which is consumed
name: queuing.${this.snakeCaseBaseName}.${this.snakeCaseEntityClass}
enabled: true
'[key.deserializer]': org.apache.kafka.common.serialization.StringDeserializer
'[value.deserializer]': ${this.packageName}.service.kafka.deserializer.${entity}Deserializer
Expand All @@ -255,8 +261,8 @@ module.exports = class extends BaseGenerator {

this.entities.forEach(entity => {
this.entityClass = entity;
this.dasherizedEntityClass = _.kebabCase(entity);
this.camelCaseEntityClass = _.camelCase(entity);
this.snakeCaseEntityClass = _.snakeCase(entity);

if (this.components.includes('producer')) {
if (producersCpt === 0) {
Expand All @@ -266,7 +272,12 @@ module.exports = class extends BaseGenerator {

kafkaProperties += `
${this.camelCaseEntityClass}:
name: ${this.dasherizedEntityClass}-topic
# This is a template topic naming convention which can be changed.
# %3Cmessage_type%3E.%3Capplication_name%3E.%3Centity_name%3E with (all in snake_case):
# - %3Cmessage_type%3E: queuing, logging, tracking, etl/db, streaming, push, user...
# - %3Capplication_name%3E: the application base name
# - %3Centity_name%3E: the entity name which is produced
name: queuing.${this.snakeCaseBaseName}.${this.snakeCaseEntityClass}
enabled: true
'[key.serializer]': org.apache.kafka.common.serialization.StringSerializer
'[value.serializer]': ${this.packageName}.service.kafka.serializer.${entity}Serializer`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ 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());
public <%= entityClass %>Consumer(@Value("${kafka.consumer.<%= camelCaseEntityClass %>.name}") final String topicName, final KafkaProperties kafkaProperties) {
super(topicName, kafkaProperties.getConsumer().get("<%= camelCaseEntityClass %>"), kafkaProperties.getPollingTimeout());
}

@Override
Expand Down

0 comments on commit eece891

Please sign in to comment.