Spring “弹簧积分误差”;“没有可用的输出通道或replyChannel标头”;

Spring “弹簧积分误差”;“没有可用的输出通道或replyChannel标头”;,spring,spring-integration,spring-integration-dsl,spring-integration-amqp,Spring,Spring Integration,Spring Integration Dsl,Spring Integration Amqp,我不知道为什么我会得到这个例外 Caused by: org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available 这只是一个简单的集成流程,但不确定我在下面的代码中遗漏了什么 @Bean Exchange messageExchange() { return ExchangeBuilder

我不知道为什么我会得到这个例外

Caused by: org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available
这只是一个简单的集成流程,但不确定我在下面的代码中遗漏了什么

  @Bean
  Exchange messageExchange() {
    return ExchangeBuilder
        .directExchange("attr")
        .durable(true)
        .build();
  }

  @Bean
  Queue queue() {
    return QueueBuilder
        .durable("attr_queue")
        .build();
  }

  @Bean
  Binding binding() {
    return BindingBuilder
        .bind(queue())
        .to(messageExchange())
        .with("attr_queue")
        .noargs();
  }

  @Bean
  IntegrationFlow deltaFlow(ConnectionFactory connectionFactory) {
    return IntegrationFlows.from(Amqp
        .inboundAdapter(connectionFactory, queue()))
        .handle(String.class, (payload, headers) -> {
          if (payload.isEmpty()) {
            log.info("Payload empty");
          } else {
            log.info("Payload : " + payload);
          }
          return payload;
        })
        .get();
  }

我曾试图接触Spring集成,但不知道为什么会出现这种异常。我所要做的就是使用
inboundAdapter
从队列读取数据,然后将其记录到控制台。代码运行正常,但当我将消息发布到队列时,会出现此异常。使用
Amqp
适配器时,是否必须始终指定
replyChannel
output channel

不,这不是AMQP通道适配器的问题。请看一下您的
手柄()
-您在那里返回了一些东西。之后就再也没有什么可以处理的了。那么,答案应该放在哪里呢?右键,进入
replyChannel
标题。但是等等,没有人,因为没有什么可以等待回复-通道适配器是单向组件


由于您对回复不做任何操作,并且框架无法从配置阶段假设您不会处理此回复,因此我们在运行时遇到了该异常。它不能做出这样的假设,因为在
handle()
之前有一个消息通道,所以您可以从其他流发送带有
replyChannel
头的消息,以此类推。但是由于这是您的代码,您可以完全控制它,您可能会假设没有人会期望从那里得到回复,因此最好从这一点停止流式传输。为此,最好使用基于单向
MessageHandler
handle()
变量,或者只返回
null
而不是
有效负载
。您也可以使用
频道(“nullChannel”)
停止流媒体。

这是一个救命稻草。谢谢!回答得很好。我认为,使用
@ServiceActivator(inputChannel=“inputQueue”)
注释的方法中存在问题,该方法返回了一些内容。我将签名更改为
void
,并且不再抛出异常。