INT-4280: Add taskScheduler() to Java DSL

JIRA: https://jira.spring.io/browse/INT-4280

To let end-user easily to inject custom `TaskScheduler` to the endpoint
add `ConsumerEndpointSpec.taskScheduler()` option

* Address PR comments
This commit is contained in:
Artem Bilan
2017-06-27 14:40:27 -04:00
committed by Gary Russell
parent 72bd4e5bcf
commit 54b0800d08
4 changed files with 71 additions and 1 deletions

View File

@@ -26,8 +26,11 @@ import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInterceptor;
@@ -427,6 +430,28 @@ public class IntegrationFlowTests {
assertEquals("foo", this.errorRecovererFlowGateway.testIt("foo"));
}
@Autowired
private MessageChannel dedicatedQueueChannel;
@Autowired
private SubscribableChannel dedicatedResults;
@Test
public void testDedicatedPollingThreadFlow() throws InterruptedException {
AtomicReference<String> threadNameReference = new AtomicReference<>();
CountDownLatch resultLatch = new CountDownLatch(1);
this.dedicatedResults.subscribe(m -> {
threadNameReference.set(Thread.currentThread().getName());
resultLatch.countDown();
});
this.dedicatedQueueChannel.send(new GenericMessage<>("foo"));
assertTrue(resultLatch.await(10, TimeUnit.SECONDS));
assertEquals("dedicatedTaskScheduler-1", threadNameReference.get());
}
@MessagingGateway
public interface ControlBusGateway {
@@ -721,6 +746,22 @@ public class IntegrationFlowTests {
}
@Bean
public IntegrationFlow dedicatedPollingThreadFlow() {
return IntegrationFlows.from(MessageChannels.queue("dedicatedQueueChannel"))
.bridge(e -> e
.poller(Pollers.fixedDelay(0).receiveTimeout(-1))
.taskScheduler(dedicatedTaskScheduler()))
.channel("dedicatedResults")
.get();
}
@Bean
public TaskScheduler dedicatedTaskScheduler() {
return new ThreadPoolTaskScheduler();
}
}
@MessagingGateway