【问题标题】:Issue with PolledProcessor on Spring cloud data flowSpring 云数据流上的 PolledProcessor 问题
【发布时间】:2021-09-29 20:56:15
【问题描述】:

我正在使用 PolledProcessor 实现一个 Spring Cloud 数据流处理器。我按照这里的例子https://spring.io/blog/2018/02/27/spring-cloud-stream-2-0-polled-consumers。下面是我的代码。我将一个带有源管道的流部署到这个处理器(源 | polled-processor)到 scdf,并让源发布了一些消息。我确认处理器每秒都会从 scdf rabbitmq 轮询消息,但result 始终是false。我去了 scdf rabbitmq 控制台,我看到那些消息都在队列中。因此,尽管处理器在代码中不断轮询,但它并没有轮询消息。我还看到队列没有消费者。看起来 scdf 没有将此处理器绑定到队列。知道为什么吗?

public interface PolledProcessor {
    @Input
    PollableMessageSource source();

    @Output
    MessageChannel dest();
}

@SpringBootApplication
@EnableBinding(PolledProcessor.class)
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Bean
    public ApplicationRunner runner(PollableMessageSource source, MessageChannel dest) {
        return args -> {
            while (true) {
                boolean result = source.poll(dest::send);
                Thread.sleep(1000);
            }
        };
    }
}

这里是源和处理器之间的队列状态

【问题讨论】:

  • 您需要编辑问题以显示 application.yml/properties 并提供版本信息 - 但我要到明天才能查看它。完成后在此处发表评论,以便我收到通知。
  • 没有application.yml/properties,因为该应用不使用任何属性。 spring cloud 数据流版本是2.6.1
  • 截图中没有消费者。您在寻找正确的队列吗?
  • 是的,没有消费者是我的问题。那是spring cloud数据流在源和处理器之间自动创建的队列,它应该将处理器作为消费者绑定到队列
  • 我的错误 - 被调查的消费者是短暂的,通常不会出现在 UI 中。我会尽快测试并回复。

标签: spring-cloud-stream spring-cloud-dataflow


【解决方案1】:

我已经测试了一个没有问题的 Spring Cloud Stream 应用程序:

@SpringBootApplication
@EnableBinding(Polled.class)
public class So69383266Application {

    public static void main(String[] args) {
        SpringApplication.run(So69383266Application.class, args);
    }

    @Bean
    public ApplicationRunner runner(PollableMessageSource source) {
        return args -> {
            while (true) {
                boolean result = source.poll(System.out::println);
                System.out.println(result);
                Thread.sleep(1000);
            }
        };
    }

}

interface Polled {

    @Input
    PollableMessageSource source();

}
false
GenericMessage [payload=byte[6], headers={...
true
false

我建议你在AmqpMessageSource.doReceive() 中设置一个断点,看看发生了什么。

编辑

以下是检查源是否从正确的队列中消费的方法:

@Bean
public ApplicationRunner runner(PollableMessageSource source) {
    return args -> {
        while (true) {
            DirectFieldAccessor dfa = new DirectFieldAccessor(source);
            log.info(dfa.getPropertyValue("source.h.advised.targetSource.target.queue").toString());
            boolean result = source.poll(System.out::println);
            System.out.println(result);
            Thread.sleep(1000);
        }
    };
}

【讨论】:

  • 如果我用 TestChannelBinder 测试它工作正常。仅当我将其作为 Spring Cloud 数据流上的处理器运行时,才会出现此问题。不知道是不是这个原因。由于此方法适用于 Spring Cloud Stream,因此这是否适用于 Spring Cloud Dataflow?
  • 是的;数据流“只是”春季云流应用程序的编排器。尝试使用兔子活页夹在本地运行它。我不是数据流专家,但您应该展示您的流定义和部署属性。
  • 这是我的流定义source | polled-processorsource 是发布消息的数据流源应用。 polled-processor 是这个处理器。我不确定如何用兔子粘合剂进行测试。你的意思是用 rabbitmq 测试这个独立的应用程序吗?如果我在本地 Spring Cloud 数据流中测试这个应用程序,它会遇到同样的问题。
  • 部署属性呢?是的;在调试器中将其作为独立的 SCSt 应用程序运行。
  • 这意味着消费者是匿名的 - 这意味着没有绑定 group 属性 - 通常 SCDF 将每个绑定放在一个组中 - 这就是为什么我希望您显示完整的流定义(不仅仅是source | polled-processor sn-p。我相信 SCDF 使用 inputoutput 作为其绑定名称(至少默认情况下) - 尝试将 source() 更改为 input()。或 @Input("input")。我不太熟悉SCDF 知道如何告诉它使用自定义绑定名称(如果可以的话)。
猜你喜欢
  • 2019-01-16
  • 1970-01-01
  • 2017-11-02
  • 1970-01-01
  • 1970-01-01
  • 2018-10-11
  • 2017-09-12
  • 1970-01-01
  • 2018-02-05
相关资源
最近更新 更多