reports-service отладил kafka
This commit is contained in:
parent
595ef708ac
commit
563d03ffe5
5 changed files with 50 additions and 28 deletions
|
|
@ -13,11 +13,23 @@ report-service
|
|||
--spring.config.location= путь к папке с файлом настроек application.properties
|
||||
--console - признак, что надо запуститься не как сервис, слушающий очередь kafka, а как утилита для генерации отчётов за текущий день/месяц и выключиться.
|
||||
|
||||
По умолчанию запускается в режиме сервиса.
|
||||
|
||||
Пример:
|
||||
|
||||
java -jar report-service.jar --spring.config.location=clearing/clearing-parent/reports-service/src/main/resources/ --console
|
||||
|
||||
Режим сервиса
|
||||
-------------
|
||||
Слушает очередь kafka "launcher-RPRT" (см. Task.createReport, ReportRequest).
|
||||
|
||||
{"id":1000,
|
||||
"requestPayload":{
|
||||
"reportId":"GREP",
|
||||
"startDate":null,
|
||||
"endDate":null
|
||||
}}
|
||||
|
||||
|
||||
Настройки
|
||||
---------
|
||||
|
|
@ -18,7 +18,7 @@ import ru.spcex.platform.imdg.iml.hazelcast.config.HazelcastClientParams;
|
|||
public class ReportsServiceSettings {
|
||||
private HazelcastClientParams hazelcast;
|
||||
private KafkaConsumerSettings kafkaConsumer;
|
||||
private KafkaProducerSettings kafkaProducer;
|
||||
// private KafkaProducerSettings kafkaProducer;
|
||||
private String reportModuleOut;
|
||||
|
||||
public HazelcastClientParams getHazelcast() {
|
||||
|
|
@ -37,13 +37,13 @@ public class ReportsServiceSettings {
|
|||
this.kafkaConsumer = kafkaConsumer;
|
||||
}
|
||||
|
||||
public KafkaProducerSettings getKafkaProducer() {
|
||||
return kafkaProducer;
|
||||
}
|
||||
|
||||
public void setKafkaProducer(KafkaProducerSettings kafkaProducer) {
|
||||
this.kafkaProducer = kafkaProducer;
|
||||
}
|
||||
// public KafkaProducerSettings getKafkaProducer() {
|
||||
// return kafkaProducer;
|
||||
// }
|
||||
//
|
||||
// public void setKafkaProducer(KafkaProducerSettings kafkaProducer) {
|
||||
// this.kafkaProducer = kafkaProducer;
|
||||
// }
|
||||
|
||||
public String getReportModuleOut() {
|
||||
return reportModuleOut;
|
||||
|
|
|
|||
|
|
@ -17,21 +17,18 @@ import ru.spcex.platform.utils.log.ExceptionUtils;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import static ru.spcex.clearing.reports.services.ReportsServiceCommand.QUEUE_RUN_REPORT_COMMAND;
|
||||
|
||||
@Service
|
||||
@Lazy // требуется получать экземпляр сервиса явно, когда надо его запустить
|
||||
public class QCommandExecutor extends QueueConsumer implements InitializingBean {
|
||||
private static final String QUEUE_RUN_REPORT_COMMAND = "GREP"; // см. Task.createReport
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
// private final ImdgId idGenerator;
|
||||
// private final KafkaSender kafkaReqProducer;
|
||||
ReportsServiceCommand reportsServiceCommand;
|
||||
ReportsServiceSettings config;
|
||||
|
||||
public QCommandExecutor(Consumer<String, Object> kafkaQueue, ImdgProvider imdgProvider,
|
||||
List<ReportWithPeriodCollector> listOfCollectors,
|
||||
ReportsServiceCommand reportsServiceCommand,
|
||||
ReportsServiceSettings config) {
|
||||
super(kafkaQueue);
|
||||
|
|
@ -45,25 +42,31 @@ public class QCommandExecutor extends QueueConsumer implements InitializingBean
|
|||
callback(ReportWithPeriodRequest.class)
|
||||
.setConsumer(this::newReportWithPeriod)
|
||||
.forDestination(Task.createReport.topic(), callbacks::put);
|
||||
init();
|
||||
}
|
||||
|
||||
private void newReportWithPeriod(BaseRequest<ReportWithPeriodRequest> reportRequest) {
|
||||
log.debug("newReportWithPeriod request received");
|
||||
|
||||
ReportWithPeriodRequest request = reportRequest.getRequestPayload();
|
||||
log.info("newReportWithPeriod request received: {}", request);
|
||||
|
||||
if (StringUtils.isBlank(request.getReportId()))
|
||||
throw new IllegalStateException("ReportID is empty");
|
||||
if (request.getStartDate() == null || request.getEndDate() == null)
|
||||
throw new IllegalStateException("StartDate or EndDate is null");
|
||||
LocalDate startDate = request.getStartDate();
|
||||
LocalDate endDate = request.getEndDate();
|
||||
if (startDate.isAfter(endDate)) throw new IllegalStateException("StartDate > EndDate");
|
||||
if (startDate == null && endDate == null) {
|
||||
endDate = LocalDate.now();
|
||||
startDate = LocalDate.of(endDate.getYear(), endDate.getMonth(), 1);
|
||||
log.debug("No date present, use default: {} - {}", startDate, endDate);
|
||||
}
|
||||
if (startDate == null || endDate == null)
|
||||
throw new IllegalStateException("StartDate or EndDate is null");
|
||||
if (startDate.isAfter(endDate))
|
||||
throw new IllegalStateException("StartDate > EndDate");
|
||||
|
||||
try {
|
||||
if (QUEUE_RUN_REPORT_COMMAND.equals(request.getReportId())) {
|
||||
log.info("Generate all report by command {}", request.getReportId());
|
||||
reportsServiceCommand.generateReportAll(startDate, endDate);
|
||||
reportsServiceCommand.generateReportAll(request.getReportId(), startDate, endDate);
|
||||
} else {
|
||||
log.info("Generate single report by command {}", request.getReportId());
|
||||
reportsServiceCommand.generateReportById(request.getReportId(), startDate, endDate);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.spcex.clearing.reports.config.element.ReportsServiceSettings;
|
||||
import ru.spcex.clearing.reports.reports.AbstractReport;
|
||||
|
|
@ -26,6 +27,8 @@ import java.util.Map;
|
|||
*/
|
||||
@Service
|
||||
public class ReportsServiceCommand implements InitializingBean {
|
||||
public static final String QUEUE_RUN_REPORT_COMMAND = "GREP"; // см. Task.createReport
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
protected ReportsServiceSettings settings;
|
||||
|
|
@ -67,12 +70,16 @@ public class ReportsServiceCommand implements InitializingBean {
|
|||
log.info("Report generator ready.");
|
||||
}
|
||||
|
||||
public void generateReportAll(LocalDate startDate, LocalDate endDate) throws IOException {
|
||||
public void generateReportAll(@Nullable String reportGroup, LocalDate startDate, LocalDate endDate) throws IOException {
|
||||
for (ReportWithPeriodCollector<?> reportDataCollector : allPeriodReports) {
|
||||
makeSingleReport(reportDataCollector, startDate, endDate);
|
||||
if (reportGroup == null || QUEUE_RUN_REPORT_COMMAND.equals(reportGroup)) {
|
||||
makeSingleReport(reportDataCollector, startDate, endDate);
|
||||
}
|
||||
}
|
||||
for (SimpleReportCollector<?> reportDataCollector : allSimpleReports) {
|
||||
makeSingleReport(reportDataCollector);
|
||||
if (reportGroup == null || QUEUE_RUN_REPORT_COMMAND.equals(reportGroup)) {
|
||||
makeSingleReport(reportDataCollector);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@ reports-service.kafka-consumer.auto-offset-reset=latest
|
|||
reports-service.kafka-consumer.linger-ms=1
|
||||
reports-service.kafka-consumer.buffer-memory=33554432
|
||||
|
||||
reports-service.kafka-producer.bootstrap-servers=localhost:9092
|
||||
reports-service.kafka-producer.acks=all
|
||||
reports-service.kafka-producer.retries=0
|
||||
reports-service.kafka-producer.batch-size=16384
|
||||
reports-service.kafka-producer.linger-ms=1
|
||||
reports-service.kafka-producer.buffer-memory=33554432
|
||||
#reports-service.kafka-producer.bootstrap-servers=localhost:9092
|
||||
#reports-service.kafka-producer.acks=all
|
||||
#reports-service.kafka-producer.retries=0
|
||||
#reports-service.kafka-producer.batch-size=16384
|
||||
#reports-service.kafka-producer.linger-ms=1
|
||||
#reports-service.kafka-producer.buffer-memory=33554432
|
||||
|
||||
reports-service.hazelcast.cluster-members=127.0.0.1:5701
|
||||
#,10.200.200.181:5701
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue