<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kevin Jain on Medium]]></title>
        <description><![CDATA[Stories by Kevin Jain on Medium]]></description>
        <link>https://medium.com/@thatskevinjain?source=rss-15464c31367f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*suJzIi__U6At8PQRt5JndA.png</url>
            <title>Stories by Kevin Jain on Medium</title>
            <link>https://medium.com/@thatskevinjain?source=rss-15464c31367f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 20:15:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thatskevinjain/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Manage queues in MongoDB using NodeJS]]></title>
            <link>https://medium.com/@thatskevinjain/manage-queues-in-mongodb-using-nodejs-6a3167807c0d?source=rss-15464c31367f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a3167807c0d</guid>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[queue]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[queue-management]]></category>
            <dc:creator><![CDATA[Kevin Jain]]></dc:creator>
            <pubDate>Wed, 22 Apr 2020 20:49:34 GMT</pubDate>
            <atom:updated>2020-05-27T14:00:30.797Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QCczgu2dY1eXFHyf" /><figcaption>Photo by <a href="https://unsplash.com/@melanie_sophie?utm_source=medium&amp;utm_medium=referral">Melanie Pongratz</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4><strong>Have you ever used queues in computer programming?</strong></h4><p>If yes, then you can jump right to the part where I explain how to implement them.</p><p>For everyone else, I would like to give you a brief introduction.</p><blockquote>As per the definition— <br>Queue is a line or sequence of people or vehicles awaiting their turn to be attended to or to proceed.</blockquote><p>We have all experienced waiting in long lines to buy items in shops or to get our cars refueled in petrol pumps, wherein we get served on a first come first serve basis.<br>Great, now let&#39;s see what it means in computing terms —</p><blockquote>Queue is a list of data items, commands, etc., stored so as to be retrievable in a definite order, usually the order of insertion.</blockquote><p>This means queues are a simple data structure that stores entities in the order they arrive and can be retrieved in the same order.</p><h4>So why do we need queues and where are they used?</h4><p>They are needed where jobs don’t have to be processed immediately but the order needs to be preserved. <em>(FIFO/LIFO).</em></p><p>They are used for a variety of applications like CPU/Disk Scheduling, IO Buffers, pipes, file IO, etc.</p><p>Say you have to send a promotional email to your entire userbase marketing your new product or send daily push notifications regarding some new discounts and offers, you can leverage queues to do that too.</p><p>You can read more about their use cases here — <br><a href="https://stackoverflow.com/questions/2392824/what-are-practical-applications-of-queues">What are the practical applications of Queues?</a></p><h3>Implementation</h3><p>You will have to fulfill the following prerequisites — <br> — MongoDB (v3.6+)<br> — NodeJS<br>In addition, we will be using an open-source library named <strong>Quiddity </strong>to manage Queues.</p><ol><li><strong>Get the library</strong><br>Clone the master branch of <a href="https://github.com/thatsKevinJain/quiddity">Quiddity Server</a><br>git clone <a href="https://github.com/thatsKevinJain/quiddity.git">https://github.com/thatsKevinJain/quiddity.git</a></li><li><strong>Run the server<br></strong>If you have set up MongoDB, you can pass the connection URL and run the server as follows<br>MONGO_URL=&lt;mongo_connection_url&gt; npm start</li></ol><p>Great, this will set up a simple server that connects to your MongoDB instance and exposes basic APIs that allow you to <strong><em>push</em></strong><em>, </em><strong><em>pull, </em></strong>and <strong><em>delete</em> </strong>messages from the queue.</p><p>Now we need to set up a consumer that communicates with these APIs, for that purpose, we will be using an npm library named <a href="https://www.npmjs.com/package/quiddity-agent"><strong>quiddity-agent</strong></a>.<br><strong>npm i quiddity-agent</strong></p><p>Then you can initialize a test queue<strong> </strong>by adding the following snippet —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/04b4dbdfe6c38fd9adab43d0028f2ab0/href">https://medium.com/media/04b4dbdfe6c38fd9adab43d0028f2ab0/href</a></iframe><p>This will create a new queue and now you can push messages easily like following —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c194c2adc81d6af33a722e3f6cbce65e/href">https://medium.com/media/c194c2adc81d6af33a722e3f6cbce65e/href</a></iframe><p>You can also pull messages to perform jobs and call <strong>done() </strong>after the job as finished processing —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c83acd826bc7fb68dd5adfe6d59761e/href">https://medium.com/media/2c83acd826bc7fb68dd5adfe6d59761e/href</a></iframe><p>You can connect to the server setup in step 2 by passing a <strong>QUIDDITY_URL </strong>in your environment.</p><p>And that&#39;s it! With a few simple steps, you can set up your own queue system. You can also run multiple agents on the same queue.</p><p>You can do a lot more with this library like — <br> — Set <strong>expiry time</strong> of messages<br> — Set <strong>polling intervals</strong> on empty queues<br> — Add <strong>custom filtering</strong> to modify queue responses<br> — Fetch <strong>dead letter queue</strong> messages<br> — <strong>Delete all messages</strong> on the queue</p><p>Check out the documentation by going to the following link — <br><a href="https://github.com/thatsKevinJain/quiddity"><strong>quiddity-server</strong></a><strong><br></strong><a href="https://www.npmjs.com/package/quiddity-agent"><strong>quiddity-agent</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*QddQGJgi5JtzJLuHnlz56A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a3167807c0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>