Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,15 @@ public final boolean isRunning() {
public final void start() {
this.lifecycleLock.lock();
try {
if (!this.running) {
if (!this.running && !this.active) {
this.active = true;
doStart();
try {
doStart();
}
catch (RuntimeException ex) {
this.active = false;
throw ex;
}
this.running = true;
logger.info(() -> "started " + this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;

import org.assertj.core.data.Percentage;
import org.junit.jupiter.api.Test;

import org.springframework.aop.framework.Advised;
Expand Down Expand Up @@ -55,6 +56,7 @@
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.scheduling.TriggerContext;
import org.springframework.stereotype.Component;
import org.springframework.test.annotation.DirtiesContext;
Expand Down Expand Up @@ -118,6 +120,34 @@ public void testGatewayExplicitReplyChannel() {
assertThat(message.getPayload()).isEqualTo("FOO");
}

@Autowired
@Qualifier("delaysBetweenPollsInput")
private MessageChannel delaysBetweenPollsInput;

@Autowired
@Qualifier("delaysBetweenPollsOutput")
private PollableChannel delaysBetweenPollsOutput;

@Test
public void noDoubleStartForEndpoints() {
this.delaysBetweenPollsInput.send(new GenericMessage<>("A,B"));

Message<?> receive1 = this.delaysBetweenPollsOutput.receive(10_000);

assertThat(receive1).isNotNull()
.extracting(Message::getPayload)
.isEqualTo("A");

Message<?> receive2 = this.delaysBetweenPollsOutput.receive(10_000);

assertThat(receive2).isNotNull()
.extracting(Message::getPayload)
.isEqualTo("B");

assertThat(receive2.getHeaders().getTimestamp() - receive1.getHeaders().getTimestamp())
.isCloseTo(500, Percentage.withPercentage(10));
}

@Configuration
@EnableIntegration
@ComponentScan
Expand Down Expand Up @@ -226,4 +256,23 @@ public String handle(String payload, @Header String foo) {

}

@Component
public static class DelaysBetweenPollsAdapter extends IntegrationFlowAdapter {

@ServiceActivator
public String handle(String payload) {
return payload;
}

@Override
protected IntegrationFlowDefinition<?> buildFlow() {
return from("delaysBetweenPollsInput")
.split(splitter -> splitter.delimiters(","))
.channel(MessageChannels.queue())
.handle(this, "handle", e -> e.poller(poller -> poller.fixedDelay(500).maxMessagesPerPoll(1)))
.channel(MessageChannels.queue("delaysBetweenPollsOutput"));
}

}

}