ScatterGather query is only send to one service

Hello,
I am using Axon server SE (version 4.5.3) and multiple standalone services (Spring apps) which are connected to the Axon server. Because I wish to get “build information” from each of the services I created a queryHandler in “common” package which is injected into each of the services. This way I have one code in one place.

When I send ScatterGather query I only receive one “build information” from only one service and the service is randomly chosen by the Axon. I tried to create a second queryHandler in one of the services and in this case ScatterGather returns two “build information” if the service is chosen by the Axon, otherwise it will return only one.

I use this call:

protected <T, V> List<T> scatterGatherMessage(V query, Class<T> responseClass) throws AxonCommunicationException {
        QueryMessage<V, T> genericQueryMessage = new GenericQueryMessage<>(query, instanceOf(responseClass));

        try {
            return queryBus.scatterGather(genericQueryMessage, 10, TimeUnit.SECONDS)
                    .map(QueryResponseMessage::getPayload)
                    .toList();
        } catch (CompletionException e) {
            throw new AxonCommunicationException("Exception in Axon communication occurred.", e);
        }
    }

Could you please push me in the correct direction?
Thank you. :slight_smile:

Hi Jan, welcome to this forum!

Pretty sure I can help you, although I will be making an assumption upfront.
But first, let me explain how a scatter-gather query is ‘scattered’ among the connected clients by Axon Server.

Each connected application has a name with Axon Server (AS for short).
These are called “components” in AS’ book.

When you have several instances of the same app, they would typically have the same application name.
When connected to Axon Server, they are different instances of the same component, based on the app name.

Now, when you do a scatter-gather query with Axon Server, AS will dispatch the request only to one instance for each component that can handle the said query.
So, in short, differing components can handle the same scatter-gather query, but for identical applications (same app-name == same component), only one instance will receive the request.

This is where the assumption comes in.
I am assuming you have the same application name for these instances.
Hence, the scatter-gather query is only sent to one of them instead of all.

Let me know whether this assumption is correct!
The fix would thus be straightforward as well: making sure the names differ.

2 Likes

Thank you very much Steven, that was exactly the problem. :slight_smile: