英文:
How to correctly migrate to Spring Cloud stream v4?
问题
我在升级到Spring Cloud Stream v4时遇到了问题,具体是在测试部分。
我已经成功重写了以下部分:
@StreamListener(Sink.INPUT)
public void processMessage(String message) {
...
重写为:
@Bean
public Consumer<String> processMessage() {
return message -> {
...
在测试中,我只是简单地使用以下方式自动装配Sink:
@Autowired
private Sink sink;
然后在测试中这样使用:
sink.input().send(message);
然而,现在无法找到Sink类了。迁移指南还在编写中,但我现在就需要升级。有人能帮忙解决如何在测试中发送消息到Sink吗?
英文:
I have some problems rewriting the app to v4 of Spring Cloud stream, more specifically the tests.
This I rewrote successfully:
@StreamListener(Sink.INPUT)
public void processMessage(String message) {
...
to:
@Bean
public Consumer<String> processMessage() {
return message -> {
...
In the test, I am auto wiring the Sink simply with:
@Autowired
private Sink sink;
and later using it as follows:
sink.input().send(message);
However, the Sink class is not found anymore. The migration guide is still being written but I need to upgrade now. Can somebody help how I can send message to the Sink in the test?
答案1
得分: 1
为了测试这种情况,您需要使用基于内存的Spring Integration通道的测试绑定程序。请参考这里的示例:https://github.com/spring-cloud/spring-cloud-stream/blob/main/core/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/function/ImplicitFunctionBindingTests.java#L406
在该测试类中,还有许多其他测试来测试各种功能绑定。旧的Sink、Source和Processor接口现在已从框架中移除,以代替功能绑定模型。
英文:
To test such a scenario, you need to use the test binder based on the in-memory Spring Integration channels. See here for an example: https://github.com/spring-cloud/spring-cloud-stream/blob/main/core/spring-cloud-stream-integration-tests/src/test/java/org/springframework/cloud/stream/function/ImplicitFunctionBindingTests.java#L406
There are many other tests that exercise the various functional bindings in that test class. The old Sink, Source and Processor interfaces are now removed from the framework in lieu of the functional binding model.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论