Axon - Cannot emit query update in different microservice

不羁的心 提交于 2021-02-11 07:13:24

问题


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.

Subscription:

    @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();
    }

Emitter:

    @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()));
    }

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

@Edit I have found a workardound for this situation:

  1. Second service instead of emitting query via queryUpdateEmitter, publishes event with list of movies
  2. First service handles this event and then emits update via 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).


回答1:


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

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).

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.

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



来源:https://stackoverflow.com/questions/62681443/axon-cannot-emit-query-update-in-different-microservice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!