INT-3887: Add receiveTimeout into the @Poller
JIRA: https://jira.spring.io/browse/INT-3887
This commit is contained in:
committed by
Gary Russell
parent
13f9ab6da8
commit
7702a6f89e
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -39,6 +39,7 @@ import org.springframework.scheduling.support.PeriodicTrigger;
|
||||
*
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
@Target({})
|
||||
@@ -92,4 +93,15 @@ public @interface Poller {
|
||||
*/
|
||||
String errorChannel() default "";
|
||||
|
||||
/**
|
||||
* Only applies to polling consumers.
|
||||
* @return the time the poll thread will wait after the trigger for a new message to arrive.
|
||||
* Defaults to 1000 (1 second).
|
||||
* For polled inbound channel adapters, whether or not the polling thread blocks
|
||||
* is dependent on the message source implementation.
|
||||
* Can be specified as 'property placeholder', e.g. {@code ${my.poller.receiveTimeout}}.
|
||||
* @since 5.1
|
||||
*/
|
||||
String receiveTimeout() default "";
|
||||
|
||||
}
|
||||
|
||||
@@ -364,6 +364,7 @@ public abstract class AbstractMethodAnnotationPostProcessor<T extends Annotation
|
||||
String maxMessagesPerPollValue = this.beanFactory.resolveEmbeddedValue(poller.maxMessagesPerPoll());
|
||||
String cron = this.beanFactory.resolveEmbeddedValue(poller.cron());
|
||||
String errorChannel = this.beanFactory.resolveEmbeddedValue(poller.errorChannel());
|
||||
String receiveTimeout = this.beanFactory.resolveEmbeddedValue(poller.receiveTimeout());
|
||||
|
||||
if (StringUtils.hasText(ref)) {
|
||||
Assert.state(!StringUtils.hasText(triggerRef) && !StringUtils.hasText(executorRef) &&
|
||||
@@ -416,6 +417,10 @@ public abstract class AbstractMethodAnnotationPostProcessor<T extends Annotation
|
||||
errorHandler.setBeanFactory(this.beanFactory);
|
||||
pollerMetadata.setErrorHandler(errorHandler);
|
||||
}
|
||||
|
||||
if (StringUtils.hasText(receiveTimeout)) {
|
||||
pollerMetadata.setReceiveTimeout(Long.parseLong(receiveTimeout));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -499,8 +504,8 @@ public abstract class AbstractMethodAnnotationPostProcessor<T extends Annotation
|
||||
for (Annotation annotation : annotations) {
|
||||
Object value = AnnotationUtils.getValue(annotation, attribute);
|
||||
if (MessagingAnnotationUtils.hasValue(value)) {
|
||||
throw new BeanDefinitionValidationException("The MessageHandler [" + handlerBeanName + "] can not" +
|
||||
" be populated because of ambiguity with annotation attributes " +
|
||||
throw new BeanDefinitionValidationException("The MessageHandler [" + handlerBeanName +
|
||||
"] can not be populated because of ambiguity with annotation attributes " +
|
||||
this.messageHandlerAttributes + " which are not allowed when an integration annotation " +
|
||||
"is used with a @Bean definition for a MessageHandler." +
|
||||
"\nThe attribute causing the ambiguity is: [" + attribute + "]." +
|
||||
|
||||
@@ -149,6 +149,7 @@ import reactor.core.publisher.Mono;
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
@ContextConfiguration(loader = NoBeansOverrideAnnotationConfigContextLoader.class,
|
||||
@@ -295,7 +296,6 @@ public class EnableIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testAnnotatedServiceActivator() throws Exception {
|
||||
this.serviceActivatorEndpoint.setReceiveTimeout(10000);
|
||||
this.serviceActivatorEndpoint.start();
|
||||
assertTrue(this.inputReceiveLatch.await(10, TimeUnit.SECONDS));
|
||||
|
||||
@@ -1239,7 +1239,9 @@ public class EnableIntegrationTests {
|
||||
|
||||
@Override
|
||||
@ServiceActivator(inputChannel = "input", outputChannel = "output", autoStartup = "false",
|
||||
poller = @Poller(maxMessagesPerPoll = "${poller.maxMessagesPerPoll}", fixedDelay = "${poller.interval}"))
|
||||
poller = @Poller(maxMessagesPerPoll = "${poller.maxMessagesPerPoll}",
|
||||
fixedDelay = "${poller.interval}",
|
||||
receiveTimeout = "${poller.receiveTimeout}"))
|
||||
@Publisher
|
||||
@Payload("#args[0].toLowerCase()")
|
||||
@Role("foo")
|
||||
@@ -1249,7 +1251,8 @@ public class EnableIntegrationTests {
|
||||
|
||||
@Override
|
||||
@ServiceActivator(inputChannel = "input1", outputChannel = "output",
|
||||
poller = @Poller(maxMessagesPerPoll = "${poller.maxMessagesPerPoll}", fixedRate = "${poller.interval}"))
|
||||
poller = @Poller(maxMessagesPerPoll = "${poller.maxMessagesPerPoll}",
|
||||
fixedRate = "${poller.interval}"))
|
||||
@Publisher
|
||||
@Payload("#args[0].toLowerCase()")
|
||||
public String handle1(String payload) {
|
||||
@@ -1285,7 +1288,8 @@ public class EnableIntegrationTests {
|
||||
/*
|
||||
* This is an error because input5 is not defined and is therefore a DirectChannel.
|
||||
*/
|
||||
/*@ServiceActivator(inputChannel = "input5", outputChannel = "output", poller = @Poller("defaultPollerMetadata"))
|
||||
/*@ServiceActivator(inputChannel = "input5", outputChannel = "output",
|
||||
poller = @Poller("defaultPollerMetadata"))
|
||||
@Publisher
|
||||
@Payload("#args[0].toLowerCase()")
|
||||
public String handle5(String payload) {
|
||||
@@ -1669,8 +1673,9 @@ public class EnableIntegrationTests {
|
||||
}
|
||||
|
||||
// Error because the annotation is on a class; it must be on an interface
|
||||
// @MessagingGateway(defaultRequestChannel = "gatewayChannel", defaultHeaders = @GatewayHeader(name = "foo", value = "FOO"))
|
||||
// public static class TestGateway2 { }
|
||||
// @MessagingGateway(defaultRequestChannel = "gatewayChannel",
|
||||
// defaultHeaders = @GatewayHeader(name = "foo", value = "FOO"))
|
||||
// public static class TestGateway2 { }
|
||||
|
||||
|
||||
public static class TestSpelFunction {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
message.history.tracked.components=input, publishedChannel, annotationTestService*
|
||||
poller.maxMessagesPerPoll=10
|
||||
poller.interval=100
|
||||
poller.receiveTimeout=10000
|
||||
global.wireTap.pattern=input
|
||||
|
||||
@@ -445,7 +445,8 @@ public class AnnotationService {
|
||||
|
||||
The `@Poller` annotation provides only simple `PollerMetadata` options.
|
||||
You can configure the `@Poller` annotation's attributes (`maxMessagesPerPoll`, `fixedDelay`, `fixedRate`, and `cron`) with property placeholders.
|
||||
If it is necessary to provide more polling options (for example, `transaction`, `advice-chain`, `error-handler`, and others), you should configure the `PollerMetadata` as a generic bean and use its bean name as the `@Poller`'s `value` attribute.
|
||||
Also, starting with version 5.1, the `receiveTimeout` option for `PollingConsumer` s is also provided.
|
||||
If it is necessary to provide more polling options (for example, `transaction`, `advice-chain`, `error-handler`, and others), you should configure the `PollerMetadata` as a generic bean and use its bean name as the `@Poller` 's `value` attribute.
|
||||
In this case, no other attributes are allowed (they must be specified on the `PollerMetadata` bean).
|
||||
Note, if `inputChannel` is a `PollableChannel` and no `@Poller` is configured, the default `PollerMetadata` is used (if it is present in the application context).
|
||||
To declare the default poller by using a `@Configuration` annotation, use code similar to the following example:
|
||||
|
||||
@@ -47,6 +47,7 @@ The following changes have been made in version 5.1:
|
||||
* <<x5.1-publisher>>
|
||||
* <<x51.-integration-graph>>
|
||||
* <<x51.-global-properties>>
|
||||
* <<x51.-poller-annotation>>
|
||||
|
||||
[[x5.1-java-dsl]]
|
||||
==== Java DSL
|
||||
@@ -222,8 +223,14 @@ See <<micrometer-integration>> for more information.
|
||||
It is now possible to add additional properties to the `IntegrationNode` s via `Function<NamedComponent, Map<String, Object>> additionalPropertiesCallback` on the `IntegrationGraphServer`.
|
||||
See <<integration-graph>> for more information.
|
||||
|
||||
[[x51.-x51.-global-properties]]
|
||||
[[x51.-global-properties]]
|
||||
=== Integration Global Properties
|
||||
|
||||
The Integration global properties (including defaults) can now be printed in the logs, when a `DEBUG` logic level is turned on for the `org.springframework.integration` category.
|
||||
See <<global-properties>> for more information.
|
||||
|
||||
[[x51.-poller-annotation]]
|
||||
=== The `receiveTimeout` for `@Poller`
|
||||
|
||||
The `@Poller` annotation now provides a `receiveTimeout` option for convenience.
|
||||
See <<configuration-using-poller-annotation>> for more information.
|
||||
|
||||
Reference in New Issue
Block a user