![]() ![]() In the Worker.execute method we call the doWork function which sends the sms messages by calling ndSms. The below code demonstrates consuming the sms_messages queue in rabbitmq. For those of you still wondering brudexRabbit is the name am giving to this container. This will pull the rabbitmq image if not available and run it with the default ports. However if you have docker you are ninja and for us ninjas we can install and setup rabbitmq with just one command. You can follow this to install rabbitMq locally. RabbitMq runs on Erlang so you have to install an Erlang runtime before installing RabbitMq. You can write worker services in any of these languages to consume messages in rabbitmq. If you are skilled enough you can write your own library in your favourite language if you don't find one. Although we are using nodejs here rabbitmq has client libraries for java,c#,python etc you can even find libraries for rust. The nodejs processes are run in a cluster using pm2. The processing of requests(sms in queue) is handled by workers consuming requests from rabbitmq. In future when this api reaches its threshold we can run multiple instances in a docker swarm or use a software load balancer like pm2 to handle the proverbial 100 requests per second. Since all this web api is doing is forwarding messages it has a high throughput and can gracefully handle as many as possible with a single instance. In the above architecture we assume a web api receives all requests and forwards them to our message queue(rabbitmq). The above diagram shows the design of our sms gateway. Better scalability: You can run multiple instances of a job without worry about duplicate processing.You can requeue a message if sending fails Higher availability and better error handling.Now that you know what RabbitMQ is, the next question is: why should you use a queue instead of inserting to a database table and processing with a job. You can read more about rabbitmq here Why use RabbitMq? Rabbitmq is lightweight easy to deploy on premise and in the cloud. As if that is not enough once you get synchronization working the processing of each job slows down.Įnter RabbitMq, rabbitmq is an open source message broker software that implements the Advanced Message Queuing Protocol (AMQP). If by some voodoo coding you get it to scale you will have to handle your own process synchronization so a single message is not processed by multiple jobs. The biggest problem with this design scalability, you can only have one job running sending the messages. This is a common anti-pattern adopted by many enterprises for handling fire and forget scenarios like this. ![]() Their strategy was inserting into an sql table and having a job pick and send the messages. ![]() Recently a developer in one of the financial institutions consulted me on strategies for managing their bulk sms gateway which was having delays in delivering to customers. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |