-
Copy the files
RabbitMQConfig.java,RabbitMqDeclarator.java, andRabbitMqPublisher.javainto a folder within your service. Ensure they are in the same Java package. -
Add the following dependency to your
pom.xml. For more detailed steps, refer to the library's README: https://github.com/Podzilla/mq-utils-lib/blob/main/README.md<dependency> <groupId>com.github.Podzilla</groupId> <artifactId>mq-utils-lib</artifactId> <version>main-SNAPSHOT</version> </dependency>
-
In the
RabbitMQConfig.javafile, add your event definitions to thePRODUCE_EVENTSandCONSUME_EVENTSsets. -
It is mandatory to have
spring.application.namedefined in yourapplication.propertiesfile. -
To listen to a specific event, use the
@RabbitListenerannotation as shown below:@RabbitListener( queues = "#{ T(com.podzilla.mq.utils.RabbitMqNaming).getQueueName(T(com.podzilla.mq.EventsConstants).ORDER_PLACED, T(com.example.demo.RabbitMQConfig).getServiceName()) }" ) public void listenToOrderPlaced(YourEventType eventPayload) { // Your message processing logic here }
Note: Change
com.example.demoto the actual package name where you placed theRabbitMQConfig.javafile.