Reputation: 1298
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());
}
}
Is it possible to use spring cloud stream functions to achieve the same result?
Upvotes: 3
Views: 1038
Reputation: 5924
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
Upvotes: 2