How can I provide a fallback on scatter/gather with NoQueryHandlerFoundException

I have an unknown number of services connected to the axon server that might answer a scatter gather query. I use the results to create a list of allowed actions based on the policies that are implemented in those services (they are used for commandHandler evaluation and query handler).

When no system answers (within a timeout of n seconds) I want to fallback to a “no actions are allowed” scenario (empty list).

However, I keep getting a NoQueryHandlerFoundException in this cases although I try/catch the redection of the Stream I get from queryGateway.scatterGather(myQuery, ResponseType.instanceOf(MyAnswer.class), 10, TimeUnit.SECONDS).

As I workaround, I implemented a QueryHandler inside my calling service, so I can ensure to get at least one (empty) result, but I would prefer a try{...} catch(NoQueryHandlerFoundException e) { return MyAnswer.EMPTY; }

How can I achieve this? I was looking at the MessageInterceptors and ExceptionHandlers but am lacking the phantasy and knowledge for using them correctly.

Can you help me out with a code fragment or a link to a working example?

If I check the SimpleQueryBus, having no handlers results in a Stream#empty returned value. You can find the snippet doing so here.

After a little digging in the axonserver-connector-java project, I found that the QueryChannelImpl is the likely culprit for returning a NoHandlerForQueryException. Honestly, I don’t believe it should do so in case of a scatter-gather query.
So, feel free to file an issue for the connector, @Jan_Galinski.

I think you have found the “best” workaround already. Simply because you cannot influence the axonserver-connector-java project with interceptors or exception handlers for this to work. So, a fallback query handler is your best bet right now.