如何在 String Cloud Stream Functional Model (v3.1+) 中创建生产者?

How to create producer in String Cloud Stream Functional Model (v3.1+)?

如何在 Spring 云流功能模型中创建生产者?
以下版本现已弃用。

@Output(OUTPUT)
MessageChannel outbound();

我知道可以通过 java Supplier 功能 class 来实现,但它会每隔一秒发送一次消息。我不需要它每秒发送一次。我将用 Kafka 替换 REST API。

有什么方法可以做到吗?

使用 StreamBridge - 参见 Sending data to an arbitrary output

Here we autowire a StreamBridge bean which allows us to send data to an output binding effectively bridging non-stream application with spring-cloud-stream. Note that preceding example does not have any source functions defined (e.g., Supplier bean) leaving the framework with no trigger to create source bindings, which would be typical for cases where configuration contains function beans. So to trigger the creation of source binding we use spring.cloud.stream.source property where you can declare the name of your sources.

如果您想从外部 Kafka 主题触发流,您还可以将 spring 云 Steam 处理器的输入绑定到该主题。 Stream bridge 提供了一个可能更清晰的抽象层,即您的非 Stream 应用程序不直接使用 Kafka API。