如何正确迁移到Spring Cloud Stream v4?

huangapple go评论47阅读模式
英文:

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&lt;String&gt; processMessage() {
        return message -&gt; {
        ...

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

在该测试类中,还有许多其他测试来测试各种功能绑定。旧的SinkSourceProcessor接口现在已从框架中移除,以代替功能绑定模型。

英文:

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.

huangapple
  • 本文由 发表于 2023年5月22日 23:17:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76307654.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定