0
@Incoming("from-processor-to-consumer")
public Multi<Void> consume(Multi<String> stream) {
    return stream.onItem()
            .invoke(msg -> {
                log.infof("consumer received %s", msg);
            })
            .onItem()
            .ignore();
}

运行此方法时会引发ClassCastException

consume has thrown an exception: java.lang.ClassCastException: class java.lang.String cannot be cast to class io.smallrye.mutiny.Multi

我可以消费Multi<String>吗?

查看SmallRye Reactive Messaging > Development Model > Consuming Payloads似乎我一次只能使用一条消息。

4

1 回答 1

1

首先,我必须承认错误信息是无用的,应该改进。

问题是您的应用程序签名。

@Incoming("from-processor-to-consumer")
@Outgoing("this-is-missing-in-your-code")
public Multi<Void> consume(Multi<String> stream) {
    return stream.onItem()
            .invoke(msg -> {
                log.infof("consumer received %s", msg);
            })
            .onItem()
            .ignore();
}

@Outgoing注释丢失。返回时,Multi,您需要说“在哪里”。

如果你的方法是终端的(意思是最终消费者),你不能注入Multi. 解决方法是使用简单的无操作方法:

@Incoming("from-processor-to-consumer")
@Outgoing("this-is-missing-in-your-code")
public Multi<String> consume(Multi<String> stream) {
    return stream.onItem()
            .invoke(msg -> {
                log.infof("consumer received %s", msg);
            });
}


@Incoming("this-is-missing-in-your-code")
void noop(String s) { }
于 2022-02-02T07:50:47.563 回答