In this section, we will implement activity tracking using RabbitMQ (https://www.rabbitmq.com), which is an AMQP implementation. We will need to refactor the domain event publishing and listening mechanism that we implemented earlier and remove the Spring's application event-related code.
At a high level, the new domain event Publisher, AmqpDomainEventPublisher
, will send domain events to RabbitMQ's Exchange, which is a fan-out exchange that binds to one or more queues. Once an Exchange receives a message, it will broadcast the message to all the queues it knows, and consumers who listen to those queues will receive the message. Figure 13.7 shows the message flows using AMQP to implement the domain event publishing and consuming:
Figure 13.7: AMQP publisher and consumers
The following shows com.taskagile.config.MessageConfiguration
, where we configure the exchange, queue, and binding:
... @Configuration public class MessageConfiguration { @Bean ...