which uses localSegment (SimpleCommandBus) injected as a bean unlike it is in MultiTenantQueryBus where for each tenant registers AxonServerQueryBus which uses localSegment (SimpleQueryBus) created each time by the builder
The above causes that if we have some message handler interceptors e.g. for auth which is a common one and try to register it to MultiTenantCommandBus and MultiTenantQueryBus then for command bus this interceptor will be multiplied as many times as there are tenants and in query bus it will be just one (as expected).
The workaround for this is to register these interceptors for the command bus not for the MultiTenantCommandBus but for the localSegment directly (as there is a registered correlation one).
In general, having localSegment as a bean is good because we can easily override it (there was some workaround e.g. to disable transaction manager) but on the other hand, it causes an issue in multitenancy by multiplying the same interceptor many times in the chain which causes other issues.
Can you resolve it somehow - still want to have the option to have localsegment as bean but to not duplicate interceptors in chain?
The be able to easily override is was the exact reason it was there.
However, we feel that for multi-tenant applications, we would ideally have some configurable LocalSegmentFactory to fulfill this purpose.
Regardless, you have found a misser in our configuration here, @KaeF, for which I want to thank you. Namely, that the multi-tenant QueryBus made a unique local segment, whereas the multi-tenant CommandBus did not.
To align both, we ensure the multi-tenant CommandBus uses unique local segments for each newly constructed tenant. If you’re curious, you can see the pull request for this here.
I believe this reoslves the problem you were facing too.
If not, be sure to reach out!
PS. Thanks for filing all these concerns with us, @KaeF.
This is how we can keep improving all the tooling we provide, so the help is much appreciated!!