Axon fails to recognize command handlers that are located in a separate microservice

I have two microservices (microservice-1 and microservice-2).

I have a CommandHandler that is located in microservice-2. When I send a command with CommandGateway from microservice-1, it returns org.axonframework.commandhandling.NoHandlerForCommandException: No handler was subscribed to command.

When I use Axon Server, Axon manages to find the CommandHandler in the separate microservice, however, when I use Kafka instead of Axon Server - it returns the exception above.

Is there any additional configuration that needs to be configured to make this work? Currently, Axon + Kafka manages to find EventHandlers that are located in separate microservices from the one where the event was invoked, but it does not manage to find Commands and SagaEventHandlers.

My application.yaml is as follows:

For microservice-1:

axon:
  snapshot:
    trigger:
      treshold:
        order: 100
  kafka:
    default-topic: axon-events
    producer:
      retries: 5
      bootstrap-servers: http://localhost:9092
      transaction-id-prefix: ordertx
    consumer:
      group-id: command-group
      bootstrap-servers: http://localhost:9092
  distributed:
    enabled: true
  serializer:
    messages: xstream
  eventhandling:
    processors:
      command-processor:
        mode: tracking
        source: kafkaMessageSource

For microservice-2:

axon:
  eventhandling:
    processors:
      command-processor:
        mode: tracking
        source: kafkaMessageSource
  kafka:
    default-topic: axon-events
    producer:
      retries: 5
      bootstrap-servers: http://localhost:9092
      transaction-id-prefix: shipment-tx
    consumer:
      group-id: command-group
      bootstrap-servers: http://localhost:9092
  distributed:
    enabled: true
  serializer:
    messages: xstream


I don't have any additional configurations.



I think you are missing command bus configuration.
https://docs.axoniq.io/reference-guide/configuring-infrastructure-components/command-processing/command-dispatching try to configure spring cloud or jgroups.

Hey Lukas,

Thanks for your reply. I didn’t know that I had to additionally configure the command bus, but it does make sense.
I will try to do that and see how it goes. I kind of find the documentation not that detailed. If you happen to have a repo where this is done then that would be great!

Thank you a lot, though.

Hey, im not sure that configuring command bus for spring cloud or jgroups would help here, since you are not using thoose.

What happens is that you have both microservices using separate replaica of axon, it might work in the docker-swarm scenario, since the stack would be merget together so you would have one endpoint of the axon server.

I’m using docker aswell for the microservice scenario, and well, i have separate compose file that boots up my proxy and axon server, and micrservices connect to that. It works just fine with axon 4.1.1 for me :slight_smile:

Hey Robert,

Thanks for your input! I will also try to compose them with docker and see how it goes.

What goes through my mind though is that when I use axon server, the microservices know how to connect to it and communicate through the axon server without using docker.
They fail to do that when I switch the axon server with kafka. I am curious, do you use only axon server in your project and not kafka?

Thanks!

Hey Filip,

Hey Robert,

Yes, you are right! Axon server does act as a discovery server which connects all distributed nodes. That is why I had the initial problem, the microservices were unaware of each other.
Now, there is the option to start using axon server as the discovery server or use a spring cloud option such as Eureka. I am currently trying to implement Eureka, but there some other problems that appear, which is a separate problem for a separate topic! :smiley:

Thank you a lot, you helped guide me in discovering the problem! <3

Hi everybody,

Firstly, I am glad to see the community is jumping in on helping with questions!

Secondly, I want to give a little background on what you stumbled upon, Filip.
You assumed that the Kafka, AMQP, SpringCloud and JGroups extensions where a one-solution replacement for Axon Server.
However, those extensions all serve a different purpose, as there is a distinct routing requirement which differs between commands, events and queries.
Axon Server acts as a one-stop solution for routing all three of them, and also serves the purpose of a dedicated Event Store solution, which is explained nicely by Allard in this presentation he did.

It thus provides an easy solution so that developers can keep focusing on building business value, instead of having to configure a new type of messaging approach.
So, the Kafka and AMQP extensions serve the purpose of routing events between services.
As events can be distributed to any listener just fine, Kafka and AMQP are pretty good fits.

In turn, SpringCloud and JGroups serve the purpose of deducing where to route a given command to.
This is required, as a command always has a single handler, and thus service discovery is needed to find out where a given service should send a command to.

For queries, there currently is no direct extension available.
There is an issue to implement a DistributedQueryBus, along the lines of the DistributedCommandBus.
As we however open sourced Axon Server, we felt the priority of working on it was lowered, in favor of having focus on other components of Axon Framework and Axon Server.

So, a little added background for everybody here; hope this sheds some light on the situation.

Cheers,
Steven