1
votes

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

1 Answers

1
votes

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.