Nowadays having an application with high availability has become a need rather than an add-on to our infrastructure.
Queuing is one way of achieving high availability. With help of a queue, you can push data to the queue and consumer would read message from the queue and do necessary processing. Even if the instance that pushed message to queue(the producer) goes down, other instance can read message(consumer) from queue and process it further.
There are various queuing options available - ActiveMQ, RabbitMQ, Kafka and lots more. For now I have used RabbitMQ for this.
To know more about RabbitMQ, you can refer documentation. Once you have RabbitMQ server up and running(default password for server is guest/guest), you can follow these steps to integrate it with AEM:
- Add an entry to your POM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>com.rabbitmq</groupId> | |
<artifactId>amqp-client</artifactId> | |
<version>3.5.3</version> | |
</dependency> |
There are some transitive dependencies that need to be taken care of. For that make following changes to maven-bundle-plugin in the pom:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<plugin> | |
<groupId>org.apache.felix</groupId> | |
<artifactId>maven-bundle-plugin</artifactId> | |
<version>2.3.7</version> | |
<configuration> | |
<instructions> | |
<Private-Package> | |
com.rabbitmq.client | |
</Private-Package> | |
<Embed-Dependency>*;scope=compile|runtime;inline=false</Embed-Dependency> | |
<Embed-Transitive>true</Embed-Transitive> | |
</instructions> | |
</configuration> | |
</plugin> |
- Using RabbitMQ API, you can push messages to the queue.
- Create a consumer that listens to the queue
Refer my github repo for sample application for this. In this sample app, I have utilized RabbitMQ for "Asynchronous Email Sending".
So queue things up and ensure that your application has high availability. :)
P.S. : You can comment here or on github in case you need help.
Thanks!!!
Vivek Sachdeva
AEM Certified Expert
Hi Vivek. I saw your profile on urbanpro, want to talk with you on AEM development. My contact number is 8861489182 (Delhi). Please call or whatsapp me, when you see this message.. thanks
ReplyDelete