本文介绍了Axon-无法在其他微服务中发出查询更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想通过queryUpdateEmitter发出查询更新但在其他模块(微服务)中时,我很烦.我有基于微服务构建的应用程序,并且两者都连接到相同的Axon Server.第一服务创建subscriptionQuery,并发送一些命令.一段时间后(通过一些命令和事件),第二个服务处理一些事件,并为第一个订阅的查询发出更新.不幸的是,这种发射似乎并没有到达订户.查询完全相同,并且位于相同的程序包中.

I'm bothering with situation when I want to emit query update via queryUpdateEmitter but in different module (microservice). I have application built upon microservices and both are connected to the same Axon Server. First service creates subscriptionQuery, and sends some commands. After a while (through few commands and events) second service handles some event, and emits update for firstly subscribed query. Unfortunately it seems like this emit doesn't get to subscriber. Queries are exactly the same and sits in the same packages.

订阅:

    @GetMapping("/refresh")
    public Mono<MovieDTO> refreshMovies() {
        commandGateway.send(
                new CreateRefreshMoviesCommand(UUID.randomUUID().toString()));

        SubscriptionQueryResult<MovieDTO, MovieDTO> refreshedMoviesSubscription =
                queryGateway.subscriptionQuery(
                        new GetRefreshedMoviesQuery(),
                        ResponseTypes.instanceOf(MovieDTO.class),
                        ResponseTypes.instanceOf(MovieDTO.class)
                );

        return refreshedMoviesSubscription.updates().next();
    }

发射器:

    @EventHandler
    public void handle(DataRefreshedEvent event) {
        log.info("[event-handler] Handling {}, movieId={}",
                event.getClass().getSimpleName(),
                event.getMovieId());
                queryUpdateEmitter.emit(GetRefreshedMoviesQuery.class, query -> true,
                        Arrays.asList(
                                MovieDTO.builder().aggregateId("as").build(),
                                MovieDTO.builder().aggregateId("be").build()));
    }

在最新版本的Axon中甚至可能出现这种情况?类似的配置,但在一项服务中按预期工作.

This situation is even possible in the newest version of Axon? Similar configuration but within one service is working as expected.

@编辑我已经找到了解决这种情况的方法:

@EditI have found a workardound for this situation:

  1. 第二项服务而不是通过queryUpdateEmitter发出查询,而是发布带有电影列表的事件
  2. 第一个服务处理此事件,然后通过queryUpdateEmitter发出更新

但是我仍然想知道是否有一种方法可以仅使用查询来执行此操作,因为对我来说这似乎很自然(commandGateways/eventGateways可以按预期工作,queryUpdateEmitter除外).

But still I'd like to know if there is a way to do this using queries only, because it seems natural to me (commandGateways/eventGateways works as expected, queryUpdateEmitter is the exception).

推荐答案

这是从 QueryUpdateEmitter 的实现开始的(无论是否使用Axon Server).

This follows from the implementation of the QueryUpdateEmitter (regardless of using Axon Server yes/no).

QueryUpdateEmitter 存储一组更新处理程序,引用发出的订阅查询.但是,它仅维护由给定JVM处理的已发布的预订查询(因为 QueryUpdateEmitter 实现未分发).

The QueryUpdateEmitter stores a set of update handlers, referencing the issued subscription queries. It however only maintains the issued subscription queries handled by the given JVM (as the QueryUpdateEmitter implementation is not distributed).

它的目的是与组件(通常是查询模型"projector")配对,该组件回答有关给定模型的查询,更新模型 并发出这些更新.

It's intent is to be paired in the component (typically a Query Model "projector") which answers queries about a given model, updates the model and emits those updates.

因此,将 QueryUpdateEmitter 操作放置在与处理查询的位置不同的(微)服务中.

Hence, placing the QueryUpdateEmitter operations in a different (micro)service as where the query is handled will not work.

这篇关于Axon-无法在其他微服务中发出查询更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 17:08