-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make more readable dispatcher module
- Loading branch information
1 parent
29d3264
commit f1592bf
Showing
11 changed files
with
199 additions
and
295 deletions.
There are no files selected for viewing
39 changes: 7 additions & 32 deletions
39
dispatcher/src/main/java/com/bipbup/config/KafkaTopicConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,34 @@ | ||
package com.bipbup.config; | ||
|
||
import org.apache.kafka.clients.admin.AdminClientConfig; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.kafka.clients.admin.NewTopic; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.kafka.config.TopicBuilder; | ||
import org.springframework.kafka.core.KafkaAdmin; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class KafkaTopicConfig { | ||
|
||
@Value("${spring.kafka.topics.answer-topic}") | ||
private String answerTopic; | ||
|
||
@Value("${spring.kafka.topics.text-update-topic}") | ||
private String textUpdateTopic; | ||
|
||
@Value("${spring.kafka.topics.callback-query-update-topic}") | ||
private String callbackQueryUpdateTopic; | ||
|
||
@Value("${spring.kafka.topics.edit-topic}") | ||
private String editTopic; | ||
|
||
@Value("${spring.kafka.bootstrap-servers}") | ||
private String server; | ||
|
||
@Bean | ||
public KafkaAdmin admin() { | ||
Map<String, Object> configs = new HashMap<>(); | ||
configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, server); | ||
|
||
return new KafkaAdmin(configs); | ||
} | ||
private final KafkaTopicProperties kafkaTopicProperties; | ||
|
||
@Bean | ||
public NewTopic answerTopic() { | ||
return TopicBuilder.name(answerTopic).build(); | ||
return TopicBuilder.name(kafkaTopicProperties.getAnswerTopic()).build(); | ||
} | ||
|
||
@Bean | ||
public NewTopic textUpdateTopic() { | ||
return TopicBuilder.name(textUpdateTopic).build(); | ||
return TopicBuilder.name(kafkaTopicProperties.getTextUpdateTopic()).build(); | ||
} | ||
|
||
@Bean | ||
public NewTopic callbackQueryUpdateTopic() { | ||
return TopicBuilder.name(callbackQueryUpdateTopic).build(); | ||
return TopicBuilder.name(kafkaTopicProperties.getCallbackQueryUpdateTopic()).build(); | ||
} | ||
|
||
@Bean | ||
public NewTopic editTopic() { | ||
return TopicBuilder.name(editTopic).build(); | ||
return TopicBuilder.name(kafkaTopicProperties.getEditTopic()).build(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
dispatcher/src/main/java/com/bipbup/config/KafkaTopicProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.bipbup.config; | ||
|
||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Getter | ||
@Setter | ||
@Configuration | ||
@ConfigurationProperties(prefix = "topics") | ||
public class KafkaTopicProperties { | ||
|
||
private String answerTopic; | ||
|
||
private String editTopic; | ||
|
||
private String textUpdateTopic; | ||
|
||
private String callbackQueryUpdateTopic; | ||
} |
19 changes: 19 additions & 0 deletions
19
dispatcher/src/main/java/com/bipbup/config/TelegramBotProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.bipbup.config; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Getter | ||
@Setter | ||
@Configuration | ||
@ConfigurationProperties(prefix = "bot") | ||
public class TelegramBotProperties { | ||
|
||
private String username; | ||
|
||
private String url; | ||
|
||
private String token; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.