Event handler not called with Axon 3.3

Hello,
I’m trying to create a simple system, with a command side and a query side in two spring-boot based services.

The aggregate inside the command side is handling the command which is written in the db, the generated event is then sent through RabbitMQ but the eventhandler inside the other service is not called.

I’ve tried so many things and I don’t know how to solve.

This is the project: https://github.com/FedericoPonzi/AxonProject/

This is the main where I’ve defined the SpringAMQPMessageSource: https://github.com/FedericoPonzi/AxonProject/blob/master/domain-management-command/src/main/java/it/uniroma1/jacopetto/domainmanagement/command/DomainManagementCommandApplication.java

Here is the query side version: https://github.com/FedericoPonzi/AxonProject/blob/master/domain-management-query/src/main/java/it/uniroma1/jacopetto/domainmanagementms/query/DomainManagementQueryApplication.java

Inside the same class, I’ve also defined the event handler:

@EventHandler

public void handle(DomainCreatedEvent evt) {

LOG.info(“Intercepted domain created event-” + evt);

//domainRepo.add(new Domain(evt.getName(), evt.getDomain(), evt.getDescription(), new Date()));

}

As a test, while I would like to handle the event in this class: https://github.com/FedericoPonzi/AxonProject/blob/master/domain-management-query/src/main/java/it/uniroma1/jacopetto/domainmanagementms/query/repositories/DomainRepository.java (for testing out I am using a simple in memory list).

I’ve searched a lot in examples online and in documentation but cannot get throuh this.
This line:

System.out.println("Message:" + message);

inside this: https://github.com/FedericoPonzi/AxonProject/blob/master/domain-management-query/src/main/java/it/uniroma1/jacopetto/domainmanagementms/query/DomainManagementQueryApplication.java actually prints - but the eventhandler is not called. Also as aside, for some reason it dosen’t print for every event sent but one every two.

As a test, I’ve also tried to create an Event with the same classpath:
https://github.com/FedericoPonzi/AxonProject/tree/master/domain-management-query/src/main/java/it/uniroma1/jacopetto/domainmanagement/command/events

But didn’t help.

Thanks for any help (also, while this is a development code which went throu many tests to get this working, I’m very open to any suggestions or other strange/unusual code - I’m new to Spring).

Hi,

the problem is in your application.yml:

axon:
eventhandling:
processors:
name:
source: “myQueueMessageSource”

Instead of name, you should specify the actual name of your processor. This defaults to the package name of the class with the @EventHandler annotated methods. You can override this by adding a @ProcesingGroup annotation on the class.

Cheers,

Hello and thanks for the fast response,
My handler’s package is: it.uniroma1.jacopetto.domainmanagementms.query.repositories

So I’ve setted inside the application.yml

axon:
  eventhandling:
    processors:
      it.uniroma1.jacopetto.domainmanagementms.query.repositories:
        source: "myQueueMessageSource"

But stil it’s not working :frowning:
This is the EventHandler’s class: https://github.com/FedericoPonzi/AxonProject/blob/master/domain-management-query/src/main/java/it/uniroma1/jacopetto/domainmanagementms/query/repositories/DomainRepository.java

Thanks for the support,
FP

I’ve had the same problem recently and got things working using only the last word of the package name. In your case “repository”

Thanks for the answer Micheal, but didn’t work :frowning:

The last word of the package name is “repositories”, so I’ve setted the application.yml like this:

axon:
  eventhandling:
    processors:
      repositories:
        source: "myQueueMessageSource"

Also, I’m not sure if is somehow related, but only 1 every 2 messages from the mq is printed here: https://github.com/FedericoPonzi/AxonProject/blob/master/domain-management-query/src/main/java/it/uniroma1/jacopetto/domainmanagementms/query/DomainManagementQueryApplication.java#L76
Thanks for help,
FP

You probably need to escape the dots. Not sure about yaml, but in property files, you need to use quotes.

What I’d recommend doing, is annotating your class with @ProcessingGroup(“somename”) and the use somename as element in your yaml file.

Cheers,

Allard

PS. You can also use javaconfig by creating an @Autowired method taking an EventProcessingConfiguration.

Thanks a lot! Adding the @ProcessingGroup notation helped. One more thing: have someone any idea why the queue may be delivering one message every two?
Thanks again :slight_smile: and have a good WE!
FP

Thanks a lot!! Now it’s working smoothly :slight_smile:

Hello Federico,

A potential problem is your RabbitMQ configuration.

You have one Queue (eventstore) configured on your command side application (https://github.com/FedericoPonzi/AxonProject/blob/master/domain-management-command/src/main/java/it/uniroma1/jacopetto/domainmanagement/command/config/AxonConfig.java). You bind this queue to the topic exchange ‘Axon.EventBus’ which is fine.

On the query side application your are using the same Queue you have configured and created on the command side. This is not a publish-subscribe model you probably want to achieve.
Your event handlers in different services (command application & query application) will compete reading the messages on the same queue. In order to implement publish-subscribe model you can configure a unique Queue for each service (application). You can do that by configuring new unique Queue on the query side application, and bind it to the same exchange ‘Axon.EventBus’. This is the simplest solution (one unique queue per service). RabbitMQ allows more sophisticated message routing…

Add in https://github.com/FedericoPonzi/AxonProject/blob/master/domain-management-query/src/main/java/it/uniroma1/jacopetto/domainmanagementms/query/config/AxonConfig.java

`

private static final String topicExchangeName = “Axon.EventBus”;
private static final String queueName = “eventstore-query”;


@Bean
Binding binding(Queue queue, TopicExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with("#"); //all
}

`

Change your SpringAMQPMessageSource configuration in https://github.com/FedericoPonzi/AxonProject/blob/master/domain-management-query/src/main/java/it/uniroma1/jacopetto/domainmanagementms/query/DomainManagementQueryApplication.java to match new query name (@RabbitListener(queues = “eventstore-query”))

Best,
Ivan