【问题标题】:AMQP pollable channel not recognised as pollableAMQP 可轮询通道未被识别为可轮询
【发布时间】:2017-02-13 17:14:04
【问题描述】:

我的 Spring 集成流程是在 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="false"。

运行我的 Spring Boot 应用程序时,我收到异常:原因:java.lang.IllegalStateException:不应为基于注释的端点指定“@Poller”,因为“actionInstructionTransformed”是一个 SubscribableChannel(不可轮询) )。

我正在使用 Spring Boot 1.4.4.RELEASE。

如何强制 actionInstructionTransformed 被识别为可轮询?

【问题讨论】:

标签: spring-integration spring-amqp


【解决方案1】:

也许您没有导入 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>

【讨论】:

  • 我将我的 Spring Boot 应用程序缩减到了最低限度 (github.com/pilif42/amqpPollableChannel),我弄清楚了为什么它在我的情况下会损坏。如果我使用与您完全相同的 context.xml,那就太好了。现在,在我的 context.xml 中,我添加以下行 。我重建、运行并得到异常:不应为基于注释的注释指定“@Poller”……请问这是为什么?请注意,我还注释掉了所有其他 Rabbit 特定配置:xml 中定义的队列和交换。
  • 有趣;通过将该 bean 添加到我的上下文中,我得到了相同的结果;由于某种原因,看起来 xml 没有被解析。正在调查...
  • 我现在找到了解决方案:我还有 。随着 ,它现在可以工作了。
  • 是的 - 我刚刚找到了相同的解决方案 - 我需要找出原因 :(
  • 祝你好运找出真正的原因。再次感谢您为我指明正确的方向。
猜你喜欢
  • 2017-08-08
  • 1970-01-01
  • 2018-12-30
  • 2017-10-16
  • 1970-01-01
  • 1970-01-01
  • 2013-08-08
  • 2021-04-19
  • 1970-01-01
相关资源
最近更新 更多