【问题标题】:Spring Kafka Cloud Function: No transaction in contextSpring Kafka Cloud 功能:上下文中没有事务
【发布时间】:2020-05-21 14:20:59
【问题描述】:

我已经开始涉足 Spring Cloud Stream 和它的云功能支持。

我在这里上传了一个示例项目来阐明这个问题 -> https://github.com/nmarquesantos/spring-cloud-function-kafka

我有一个项目以反应方式公开一些功能,使用 kafka 作为消息代理。

该函数接收一个 Flux 并继续通过 Reactive Mongo 库保存元素。然后它通过另一个通量返回更新的资源。

@Service
public class ExampleCloudFunction {

@Autowired
private PlayerRepository playerRepository;

@Bean
public Function<Flux<Player>, Flux<Player>> playerUpdate() {
    return flux -> flux.flatMap(player -> playerRepository.save(player)).log("Saved player");
}

@PollableBean
public Supplier<Flux<Player>> playerFeeder() {
   return () -> Flux.just(new Player(UUID.randomUUID().toString(), "Ronaldo"));
}
}

playerUpdate 函数是错误发生的地方。 playerFeeder 只是我创建的一个函数,用于发送数据以重现问题。在现实生活中,这将来自不同的服务。

通过运行我上面提到的示例项目,这是错误的 sn-p:

2020-05-21 22:13:40.842 ERROR 1884 --- [container-0-C-1] onfiguration$FunctionToDestinationBinder : Failed to process the following content which will be dropped: Context1{reactor.onNextError.localStrategy=reactor.core.publisher.OnNextFailureStrategy$ResumeStrategy@2c3e726}

org.springframework.transaction.reactive.TransactionContextManager$NoTransactionInContextException: No transaction in context

2020-05-21 22:13:41.853 ERROR 1884 --- [container-0-C-1] onfiguration$FunctionToDestinationBinder : Failed to process the following content which will be dropped: Context1{reactor.onNextError.localStrategy=reactor.core.publisher.OnNextFailureStrategy$ResumeStrategy@2c3e726}

org.springframework.transaction.reactive.TransactionContextManager$NoTransactionInContextException: No transaction in context

我很难理解我做错了什么,在我的搜索中找不到太多信息。

【问题讨论】:

    标签: spring-kafka project-reactor spring-cloud-stream spring-cloud-function


    【解决方案1】:

    Spring for Apache Kafka 目前不支持反应式事务。

    【讨论】:

    • 所以这是必须避免将 spring kafka 与响应式存储库一起使用的情况吗?
    • kafka 数据的异步处理很棘手,因为不确认离散消息,只维护每个分区的偏移量。我们只是还没有调查它。我打开了一个问题。
    • 好的,非常感谢 Gary :) 现在我将研究使用非反应性存储库。
    • 哦;对不起;我假设您正在尝试对 Kafka 使用反应式事务;如果您只想使用 Mongo 进行响应式交易;看起来您需要开始交易。见here。 (我关于异步和 Kafka 的 cmets 仍然适用)
    • 我只是想链接发布者,即链接来自 kafka 的通量,然后从响应式 mongo 接收输出以将其发布到另一个主题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-23
    • 1970-01-01
    • 1970-01-01
    • 2019-12-22
    • 2020-10-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多