Spring Cloud Stream Supplier 功能模型 [英] Spring Cloud Stream Supplier function model

查看:46
本文介绍了Spring Cloud Stream Supplier 功能模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 spring cloud stream 和新功能支持配置,但我在理解如何实现与注释配置相同的结果时遇到问题.

I am trying to use spring cloud stream and the new functions support for configuration but I am having a problem to understand how to achieve the same result I would have with annotation configuration.

每次创建用户时,我都需要向代理发送消息.使用基于注释的配置,我可以像这样完成它:

I need to send a message to the brooker, every time a user is created. With the annotation based configuration I could accomplish it like this:

 public UserProducer {
    
    @Autowired
    private final Source source;
    
    @Autowired
    private final UserRepository repository;

    public void saveUser(User user) {
        repository.save(user);
        source.output().send(MessageBuilder.withPayload(user).build());
    }
 }

是否可以使用spring cloud流函数来达到同样的效果?

Is it possible to use spring cloud stream functions to achieve the same result?

推荐答案

您可以使用新的 StreamBridge API 来做到这一点.请参阅此处的文档:https://cloud.spring.io/spring-cloud-static/spring-cloud-stream/3.0.6.RELEASE/reference/html/spring-cloud-stream.html#_using_streambridge

You can use the new StreamBridge API for doing that. See the docs here: https://cloud.spring.io/spring-cloud-static/spring-cloud-stream/3.0.6.RELEASE/reference/html/spring-cloud-stream.html#_using_streambridge

这篇关于Spring Cloud Stream Supplier 功能模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆