I’m also using AMQP in a POC and Axon sends a message to rabbitMQ that contains all the data in the aggregate… which is not the desired functionality. I would want the message to contain only guid generated for the entity (not the aggregate guid) the entity that is persisted to a SQL database. Rabbit will then push the message to another service that will use the query api to get the entire entity. We don’t want all the entity data in the rabbitMQ message because this queue will be public.
I was wondering if I could intercept the message before it is sent to the queue and change what is being sent, but without affecting what is being sent to the EventStore. Not sure if MessageDispatchInterceptor is the best candidate for this and if there is any example out there on how to use it…
Also, not sure if there is some sort of annotation that can be added to the aggregate fields so they don’t get included in the message sent to rabbitMQ…
you say “Axon send a message […] that contains all the data in the aggregate”. Actually, Axon just sends the Event. If the entire aggregate is sent, that probably means your aggregate is part of the event itself, which would be a design issue that needs some attention.
What you’re looking for is not an interceptor, but the AMQPMessageConverter. It is used by the SpringAMQPPublisher and SpringAMQPMessageSource when sending and receiving messages to and from AMQP, respectively. Basically, it defines how you want messages on AMQP to be structured.
In your case, you could create a small message with only identifiers.
I will play around with the AMQPMessageConverter and will use a basic POJO class that serializes to { "event": "MyEntityCreatedEvent", "guid": "some-guid" }...
Thanks!
I have been using Axon, for about 2 weeks now, so AMQPMessageConverter is new territory for me. I have figured out I need to create a SpringAMQPPublisher bean where I create my publisher and and pass it the message converter bean:
you don’t need to wrap your AmqpEntity in a DomainEventMessage. You could pass that class (in serialized form) directly as the contents of the message instead.
That would make the code quite a bit simpler.
I have a usecase where I want to customize the routing key, were you able to customize the routing key in the application. Also if you have a git for your source code can you forward it to me.