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() {