[英]How to create producer in String Cloud Stream Functional Model (v3.1+)?
How can I create producer in Spring Cloud Stream Functional Model?如何在 Spring 云 Stream 功能 Model 中创建生产者?
The following version is deprecated now.以下版本现已弃用。
@Output(OUTPUT)
MessageChannel outbound();
I know that it is possible to achieve by java Supplier
functional class, but it will send message every one second.我知道可以通过 java
Supplier
功能 class 来实现,但它会每隔一秒发送一次消息。 I don't need it to send every second.我不需要它每秒发送一次。 I am going to replace REST API with with Kafka.
我将用 Kafka 替换 REST API。
Are there any ways to do that?有没有办法做到这一点?
Use the StreamBridge
- see Sending data to an arbitrary output .使用
StreamBridge
- 请参阅将数据发送到任意 output 。
Here we autowire a
StreamBridge
bean which allows us to send data to an output binding effectively bridging non-stream application withspring-cloud-stream
.在这里,我们自动装配一个
StreamBridge
bean,它允许我们将数据发送到 output 绑定,有效地将非流应用程序与spring-cloud-stream
桥接。 Note that preceding example does not have any source functions defined (eg,Supplier
bean) leaving the framework with no trigger to create source bindings, which would be typical for cases where configuration contains function beans.请注意,前面的示例没有定义任何源函数(例如,
Supplier
bean),使框架没有创建源绑定的触发器,这对于配置包含 function bean 的情况很典型。 So to trigger the creation of source binding we usespring.cloud.stream.source
property where you can declare the name of your sources.因此,为了触发源绑定的创建,我们使用
spring.cloud.stream.source
属性,您可以在其中声明源的名称。
If you want to trigger a stream from an external Kafka topic, you can also bind a spring cloud steam processor's input to that topic.如果您想从外部 Kafka 主题触发 stream,您还可以将 spring 云蒸汽处理器的输入绑定到该主题。 The stream bridge provides a layer of abstraction that may be cleaner, Ie, your non-stream application does not use the Kafka API directly.
stream 桥提供了一个可能更干净的抽象层,即您的非流应用程序不直接使用 Kafka API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.