From e9ee7d93146f47f9cfbf634ce30701e80ac2074d Mon Sep 17 00:00:00 2001 From: bgehrels Date: Tue, 23 May 2017 17:13:57 +0200 Subject: [PATCH] #23 - fixing the scheduling --- .../EventTransmissionScheduler.java | 26 +++++++++++++++++++ .../NakadiProducerAutoConfiguration.java | 4 --- 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 nakadi-producer-spring-boot-starter/src/main/java/org/zalando/nakadiproducer/EventTransmissionScheduler.java diff --git a/nakadi-producer-spring-boot-starter/src/main/java/org/zalando/nakadiproducer/EventTransmissionScheduler.java b/nakadi-producer-spring-boot-starter/src/main/java/org/zalando/nakadiproducer/EventTransmissionScheduler.java new file mode 100644 index 00000000..ea5746fc --- /dev/null +++ b/nakadi-producer-spring-boot-starter/src/main/java/org/zalando/nakadiproducer/EventTransmissionScheduler.java @@ -0,0 +1,26 @@ +package org.zalando.nakadiproducer; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.zalando.nakadiproducer.transmission.impl.EventTransmitter; + +@Component +public class EventTransmissionScheduler { + private final EventTransmitter eventTransmitter; + private final boolean scheduledTransmissionEnabled; + + @Autowired + public EventTransmissionScheduler(EventTransmitter eventTransmitter, @Value("${nakadi-producer.scheduled-transmission-enabled:true}") boolean scheduledTransmissionEnabled) { + this.eventTransmitter = eventTransmitter; + this.scheduledTransmissionEnabled = scheduledTransmissionEnabled; + } + + @Scheduled(fixedDelayString = "${nakadi-producer.transmission-polling-delay:1000}") + protected void sendEventsIfSchedulingEnabled() { + if (scheduledTransmissionEnabled) { + eventTransmitter.sendEvents(); + } + } +} diff --git a/nakadi-producer-spring-boot-starter/src/main/java/org/zalando/nakadiproducer/NakadiProducerAutoConfiguration.java b/nakadi-producer-spring-boot-starter/src/main/java/org/zalando/nakadiproducer/NakadiProducerAutoConfiguration.java index b8754b35..73271b6b 100644 --- a/nakadi-producer-spring-boot-starter/src/main/java/org/zalando/nakadiproducer/NakadiProducerAutoConfiguration.java +++ b/nakadi-producer-spring-boot-starter/src/main/java/org/zalando/nakadiproducer/NakadiProducerAutoConfiguration.java @@ -168,10 +168,6 @@ public EventTransmissionService eventTransmissionService(EventLogRepository even return new EventTransmissionService(eventLogRepository, nakadiPublishingClient, objectMapper); } - @Scheduled(fixedDelayString = "${nakadi-producer.transmission-polling-delay:1000}") - protected void sendEventsIfSchedulingEnabled(EventTransmitter eventTransmitter) { - eventTransmitter.sendEvents(); - } @PostConstruct public void migrateFlyway() {