Reading time: 2 – 4 minutes
At work, we’ve decided to start using enterprise queuing applications for ease of communication between our ColdFusion and .Net projects.
For those who don’t know how queues work, if I had to summarize it I would say it’s like a database that stores all the messages sent from diverse systems (even in different clusters), and awaits until a consumer (queue subscriber) picks them up.
Queues accept pretty much any kind of string you throw at them, so you could for example give it JSON or XML if you wanted to store anything a bit more complex than an ID for example.
You then write specific consumers that only listen to certain queues, and once they have received and acknowledged the message, they then move on to pick up the next item in the queue.
The queues we will be seeing in this post are FIFO type queues, which means the first item you chuck into the queue, will be theoretically the first to come out. I say “theoretically” because you could tinker with this and prioritise the order your queue serves stuff.
A simple queue with multiple consumers could be represented the following way:
What is important to notice here, is that items will be picked up on a round-robin fashion, meaning no one item could be picked up by two consumers, and no one consumer would be “greedy” and pick up more items than the others.
To illustrate this, I will use an email queue as an example. So image the following scenario:
- You have an emailing system, and all it does is… well send emails.
- Your online store sends a confirmation email to every client after they have purchased an item. And this step is important, as it provides the customer with information about their purchase.
- Your application does not need to know it sends emails, therefore all it needs to do is say: “Hey, someone’s made an order and I’ve processed it”
What the last point it trying to say, is that an application doesn’t necessarily need to have things that aren’t related to its main purpose (selling products in this case). Obviously this solution won’t be suitable for every single case, but in a similar occasion, it came to be really suitable at the company I currently work for.