首页 > 解决方案 > Spring Cloud Stream - 发送时出现 StreamBridge 错误

问题描述

我正在使用 Spring Cloud Stream 3.1.3 和带有模式注册表的 binder kafka 开发一个应用程序。这是我为 Producer 写的课程

@Slf4j
@EnableAutoConfiguration
@Component
public class Producer {

    private static final String PARTITION_KEY = "partitionKey";
    private static final String MESSAGE_ID = "messageId";

    @Autowired
    private StreamBridge streamBridge;

    public void produce(int messageId, Object message) {
        log.info("Sending test message through Kafka: {}", message);
        Message<Object> toProduce = MessageBuilder
                .withPayload(message)
                .setHeader(PARTITION_KEY, messageId)
                .build();

        streamBridge.send("produceMessage-out-0", toProduce);
    }
}

streamBridge.send调用时出现此错误:

java.lang.ClassCastException: class org.springframework.cloud.stream.function.StreamBridge$$Lambda$1557/0x0000000800ab4c40 cannot be cast to class org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInv
ocationWrapper (org.springframework.cloud.stream.function.StreamBridge$$Lambda$1557/0x0000000800ab4c40 and org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry$FunctionInvocationWrapper are in unnamed module of
loader 'app')

帮助表示赞赏。谢谢

编辑:我发现这个问题描述了我的问题。

https://github.com/spring-cloud/spring-cloud-stream/issues/2101

是否有解决方法可以使我的代码与 3.1.3 版本一起使用?

标签: spring-bootspring-cloud-streamspring-cloud-stream-binder-kafka

解决方案


推荐阅读