My Spring Integration流程在xml中定义如下(注意我已删除了打开/关闭字符,因为xml在我的问题中没有正确显示):
<int-amqp:channel id="actionInstructionTransformed" message-driven="false"/>
<int-xml:unmarshalling-transformer
input-channel="actionInstructionXmlValid" output-channel="actionInstructionTransformed"
unmarshaller="actionInstructionMarshaller" />
我有一个定义的轮询器:
<int:poller id="customPoller" default="true" trigger="customPeriodicTrigger" task-executor="customTaskExecutor" max-messages-per-poll="${poller.maxMessagesPerPoll}" error-channel="drsGatewayPollerError" />
<int:transactional propagation="REQUIRED" read-only="true" transaction-manager="transactionManager" />
</int:poller>
在Java中,我的消费者定义为:
@Transactional(propagation = Propagation.REQUIRED, readOnly = true, value = "transactionManager")
@ServiceActivator(inputChannel = "actionInstructionTransformed", poller = @Poller(value = "customPoller"),
adviceChain = "actionInstructionRetryAdvice")
public final void processInstruction(final ActionInstruction instruction)
从文档(http://docs.spring.io/autorepo/docs/spring-integration/4.0.2.RELEASE/reference/html/amqp.html)中,我了解actionInstructionTransformed应该是可轮询的,因为我添加了message-driven =&#34; false&#34;。
运行我的Spring Boot应用程序时,我遇到异常:引起:java.lang.IllegalStateException:A&#39; @ Poller&#39;不应该为基于注释的端点指定,因为&#39; actionInstructionTransformed&#39;是SubscribableChannel(不可轮询)。
我正在使用Spring Boot 1.4.4.RELEASE。
如何强制actionInstructionTransformed被识别为可轮询?
答案 0 :(得分:0)
也许您没有导入XML?在这种情况下,框架将为服务激活器输入通道创建DirectChannel
。
这对我来说很好......
@SpringBootApplication
@ImportResource("context.xml")
public class So42209741Application {
public static void main(String[] args) throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(So42209741Application.class, args);
context.getBean("pollable", MessageChannel.class).send(new GenericMessage<>("foo"));
Thread.sleep(10000);
context.close();
}
@ServiceActivator(inputChannel = "pollable", poller = @Poller(fixedDelay = "5000"))
public void foo(String in) {
System.out.println(in);
}
}
context.xml中
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int-amqp="http://www.springframework.org/schema/integration/amqp"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/amqp http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd">
<int-amqp:channel id="pollable" message-driven="false" />
</beans>