Implement ProcessorAPIWebClient
This commit is contained in:
@@ -7,6 +7,7 @@ dependencies {
|
||||
implementation project(':support')
|
||||
// https://projectreactor.io/docs/core/release/reference/#debug-activate
|
||||
implementation 'org.springframework.boot:spring-boot-starter-webflux'
|
||||
implementation 'org.springframework.boot:spring-boot-configuration-processor'
|
||||
implementation 'org.telegram:telegrambots:5.3.0'
|
||||
|
||||
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
|
||||
|
||||
@@ -2,6 +2,9 @@ package com.myoa.engineering.crawl.ppomppu.receiver;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
|
||||
import com.myoa.engineering.crawl.ppomppu.receiver.configuration.properties.TelegramBotProperties;
|
||||
|
||||
/**
|
||||
* ReceiverApplication
|
||||
@@ -10,6 +13,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
*
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableConfigurationProperties({ TelegramBotProperties.class })
|
||||
public class ReceiverApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -8,8 +8,9 @@ import org.telegram.telegrambots.meta.TelegramBotsApi;
|
||||
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
|
||||
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
|
||||
|
||||
import com.myoa.engineering.crawl.ppomppu.receiver.handler.message.MessageHandler;
|
||||
import com.myoa.engineering.crawl.ppomppu.receiver.configuration.properties.TelegramBotProperties;
|
||||
import com.myoa.engineering.crawl.ppomppu.receiver.dispatch.MessageDispatcher;
|
||||
import com.myoa.engineering.crawl.ppomppu.receiver.handler.message.MessageHandler;
|
||||
|
||||
/**
|
||||
* TelegramBotConfiguration
|
||||
@@ -20,9 +21,6 @@ import com.myoa.engineering.crawl.ppomppu.receiver.dispatch.MessageDispatcher;
|
||||
@Configuration
|
||||
public class TelegramBotConfiguration {
|
||||
|
||||
private static final String BOT_TOKEN = ""; // TODO extract to property
|
||||
private static final String BOT_NAME = ""; // TODO extract to property
|
||||
|
||||
@Bean
|
||||
public TelegramBotsApi telegramBotsApi(MessageDispatcher messageDispatcher) throws TelegramApiException {
|
||||
TelegramBotsApi api = new TelegramBotsApi(DefaultBotSession.class);
|
||||
@@ -31,7 +29,8 @@ public class TelegramBotConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageDispatcher messageDispatcher(List<MessageHandler> messageHandlers) {
|
||||
return new MessageDispatcher(messageHandlers, BOT_TOKEN, BOT_NAME);
|
||||
public MessageDispatcher messageDispatcher(List<MessageHandler> messageHandlers,
|
||||
TelegramBotProperties botProperties) {
|
||||
return new MessageDispatcher(messageHandlers, botProperties.getName(), botProperties.getToken());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.receiver.configuration.properties;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.ConstructorBinding;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* TelegramBotProperties
|
||||
* @author Shin Woo-jin (woo-jin.shin@linecorp.com)
|
||||
* @since 2021-09-05
|
||||
*
|
||||
*/
|
||||
@Getter
|
||||
@ConstructorBinding
|
||||
@ConfigurationProperties(prefix = "telegram.bot")
|
||||
public class TelegramBotProperties {
|
||||
private final String name;
|
||||
private final String token;
|
||||
|
||||
public TelegramBotProperties(final String name, final String token) {
|
||||
this.name = name;
|
||||
this.token = token;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.receiver.controller.v1;
|
||||
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.myoa.engineering.crawl.ppomppu.receiver.service.ProcessorAPIService;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.code.PpomppuBoardName;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* EventAPIController
|
||||
* @author Shin Woo-jin (woo-jin.shin@linecorp.com)
|
||||
* @since 2021-09-05
|
||||
*
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/")
|
||||
public class EventAPIController {
|
||||
|
||||
private final ProcessorAPIService processorAPIService;
|
||||
|
||||
public EventAPIController(ProcessorAPIService processorAPIService) {
|
||||
this.processorAPIService = processorAPIService;
|
||||
}
|
||||
|
||||
@PostMapping("/exploit/parsePpomppuRSS/{boardName}")
|
||||
public Mono<String> parsePpomppuRSS(@PathVariable("boardName") PpomppuBoardName boardName) {
|
||||
return processorAPIService.emitParseEvent(boardName);
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,13 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class MessageDispatcher extends TelegramLongPollingBot {
|
||||
|
||||
private final List<MessageHandler> messageHandlers;
|
||||
private final String botToken;
|
||||
private final String botName;
|
||||
private final String botToken;
|
||||
|
||||
public MessageDispatcher(List<MessageHandler> messageHandlers, String botToken, String botName) {
|
||||
public MessageDispatcher(List<MessageHandler> messageHandlers, String botName, String botToken) {
|
||||
this.messageHandlers = messageHandlers;
|
||||
this.botToken = botToken;
|
||||
this.botName = botName;
|
||||
this.botToken = botToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,6 @@ public class CommonTextHandler implements TextMessageHandler {
|
||||
@Override
|
||||
public void handle(Message message) {
|
||||
log.info("CommonTextHandler : {}", message.getText());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,32 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.receiver.infrastructure.client;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import java.util.List;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.code.PpomppuBoardName;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
@Component
|
||||
public class ProcessorAPIWebClient {
|
||||
|
||||
|
||||
@Value("${webclient.some}")
|
||||
@Value("${webclient.base-url}")
|
||||
private String baseUrl;
|
||||
|
||||
private final WebClient webClient;
|
||||
|
||||
public ProcessorAPIWebClient(WebClient.Builder webClientBuilder) {
|
||||
this.webClient = webClientBuilder.baseUrl("soundhoundfound-processor:20080")
|
||||
.build();
|
||||
this.webClient = webClientBuilder.baseUrl("http://localhost:20081")
|
||||
.build();
|
||||
}
|
||||
|
||||
public Mono<String> emitParseEvent(PpomppuBoardName boardName) {
|
||||
return webClient.post()
|
||||
.uri("/api/v1/crawl/boards/{boardName}", boardName)
|
||||
.exchangeToMono(e -> e.bodyToMono(new ParameterizedTypeReference<String>() {}))
|
||||
.publishOn(Schedulers.boundedElastic());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.receiver.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.myoa.engineering.crawl.ppomppu.receiver.infrastructure.client.ProcessorAPIWebClient;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.code.PpomppuBoardName;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* ProcessorAPIService
|
||||
* @author Shin Woo-jin (woo-jin.shin@linecorp.com)
|
||||
* @since 2021-09-05
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ProcessorAPIService {
|
||||
|
||||
private final ProcessorAPIWebClient processorAPIWebClient;
|
||||
|
||||
public ProcessorAPIService(ProcessorAPIWebClient processorAPIWebClient) {
|
||||
this.processorAPIWebClient = processorAPIWebClient;
|
||||
}
|
||||
|
||||
public Mono<String> emitParseEvent(PpomppuBoardName boardName) {
|
||||
return processorAPIWebClient.emitParseEvent(boardName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.myoa.engineering.crawl.ppomppu.receiver.shceduler;
|
||||
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.myoa.engineering.crawl.ppomppu.receiver.service.ProcessorAPIService;
|
||||
import com.myoa.engineering.crawl.ppomppu.support.dto.code.PpomppuBoardName;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* ParseEventEmitter
|
||||
* @author Shin Woo-jin (woo-jin.shin@linecorp.com)
|
||||
* @since 2021-09-05
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@EnableScheduling
|
||||
public class ParseEventEmitter {
|
||||
|
||||
private final ProcessorAPIService processorAPIService;
|
||||
|
||||
public ParseEventEmitter(ProcessorAPIService processorAPIService) {
|
||||
this.processorAPIService = processorAPIService;
|
||||
}
|
||||
|
||||
@Scheduled(fixedRate = 60 * 1000L)
|
||||
public void emitDomesticBoard() {
|
||||
log.info("[emitDomesticBoard] trigger fired!");
|
||||
processorAPIService.emitParseEvent(PpomppuBoardName.PPOMPPU_DOMESTIC).block();
|
||||
}
|
||||
|
||||
@Scheduled(fixedRate = 300 * 1000L)
|
||||
public void emitOverseaBoard() {
|
||||
log.info("[emitOverseaBoard] trigger fired!");
|
||||
processorAPIService.emitParseEvent(PpomppuBoardName.PPOMPPU_OVERSEA).block();
|
||||
}
|
||||
}
|
||||
@@ -3,4 +3,5 @@ spring:
|
||||
activate:
|
||||
on-profile: development
|
||||
import:
|
||||
- classpath:/development/webclient.yml
|
||||
- classpath:/webclient-development.yml
|
||||
- classpath:/temppassword.yml
|
||||
|
||||
@@ -6,5 +6,5 @@ spring:
|
||||
freemarker:
|
||||
enabled: false
|
||||
|
||||
webclient:
|
||||
some: not-test
|
||||
server:
|
||||
port: 20080
|
||||
5
receiver/src/main/resources/webclient-development.yml
Normal file
5
receiver/src/main/resources/webclient-development.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
webclient:
|
||||
base-url: http://localhost:20081
|
||||
units:
|
||||
- unit-name: processor-api
|
||||
base-url: http://localhost:20081
|
||||
5
receiver/src/main/resources/webclient-production.yml
Normal file
5
receiver/src/main/resources/webclient-production.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
webclient:
|
||||
base-url: http://ppomppu_notifier_processor:20080
|
||||
units:
|
||||
- unit-name: processor-api
|
||||
base-url: http://ppomppu_notifier_processor:20080
|
||||
Reference in New Issue
Block a user