gpt4 book ai didi

java - spring.cloud.stream.source 到底做了什么?

转载 作者:行者123 更新时间:2023-12-05 02:39:13 27 4
gpt4 key购买 nike

我正在尝试了解 Spring Cloud Streams 的新功能模型是如何工作的,以及配置在幕后是如何实际工作的。

我无法弄清楚的属性之一是 spring.cloud.stream.source

这个属性实际上意味着什么?

我无法理解 documentation :

Note that preceding example does not have any source functions defined(e.g., Supplier bean) leaving the framework with no trigger to createsource bindings, which would be typical for cases where configurationcontains function beans. So to trigger the creation of source bindingwe use spring.cloud.stream.source property where you can declare thename of your sources. The provided name will be used as a trigger tocreate a source binding.

如果我不需要供应商怎么办?

究竟什么是源绑定(bind),为什么它很重要?

如果我只想生成消息主题怎么办?我还需要这个属性吗?

我也无法理解它是如何在示例中使用的 here .

最佳答案

Spring Cloud 流找java.util Function<?, ? , Consumer<?> , Supplier<?> bean 并为它们创建绑定(bind)。

在供应商的情况下,框架会轮询供应商(默认情况下每秒一次)并发送结果数据。

例如

@Bean
public Supplier<String> output() {
return () -> "foo";
}
spring.cloud.stream.bindings.output-out-0.destination=bar

将发送foo到目的地bar每秒。

但是,如果您不需要轮询源,但您想要配置一个可以向其发送任意数据的绑定(bind),该怎么办。输入 spring.cloud.stream.source .

spring.cloud.stream.source=output
spring.cloud.stream.bindings.output-out-0.destination=bar

允许您向流桥发送任意数据

bridge.send("output-out-0", "test");

换句话说,它允许您配置一个或多个可以在 StreamBridge 中使用的输出绑定(bind);否则,当您发送到网桥时,绑定(bind)是动态创建的。

关于java - spring.cloud.stream.source 到底做了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69207510/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com