【问题标题】:Spring Integration error "no output-channel or replyChannel header available"Spring集成错误“没有可用的输出通道或replyChannel标头”
【发布时间】:2018-06-12 15:58:38
【问题描述】:

我不确定为什么会出现异常

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 Integration,但不确定为什么会出现此异常。我要做的就是使用inboundAdapter 从队列中读取数据并将其记录到控制台。代码运行良好,但是当我将消息发布到队列时,我得到了这个异常。在使用Amqp 适配器时,我是否必须始终指定replyChanneloutput-channel

【问题讨论】:

    标签: spring spring-integration spring-integration-dsl spring-integration-amqp


    【解决方案1】:

    不,这不是 AMQP 通道适配器问题。请看你的handle() - 你在那里返回一些东西。之后没有任何东西可以处理该回报。那么,回复应该去哪里呢?对,进入replyChannel 标头。但是等等,没有人,因为没有什么可以等待回复 - Channel Adapter 是单向组件。

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

    【讨论】:

    • 这是救命稻草。
    • 谢谢!很好的答案。我在一个用@ServiceActivator(inputChannel = "inputQueue") 注释的方法中解决了这个问题,它返回了一些东西。我将签名更改为void,并且不再抛出异常。
    猜你喜欢
    • 2018-04-10
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    • 2022-01-17
    • 1970-01-01
    • 2016-11-26
    相关资源
    最近更新 更多