# RabbitMQ, Kafka

# Message queues (RabbitMQ, Kafka)

# Message queues (RabbitMQ, Kafka) in general

<div class="WaaZC" id="bkmrk-message-queues-like-" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc" data-hveid="CAcQAQ" data-ved="2ahUKEwj6mPnQ8_qQAxUccWwGHbRUE9AQo_EKegQIBxAB" style="margin: 0px 0px 10px;"><span data-huuid="7285565964511541117">Message queues like RabbitMQ and Kafka are fundamental components in distributed systems, facilitating asynchronous communication and decoupling between different services or applications. </span><span data-huuid="7285565964511541270">They act as intermediaries, storing messages from producers until consumers are ready to process them.<span class="pjBG2e" data-cid="4014f112-e4d0-458e-aa62-f1a280d605bc"><span class="UV3uM" style="white-space: nowrap;"> </span></span></span><div class="NPrrbc" data-cid="4014f112-e4d0-458e-aa62-f1a280d605bc" data-uuids="7285565964511541117,7285565964511541270" style="margin-inline-end: 6px; vertical-align: middle; display: inline-flex;"><div aria-label="View related links" class="BMebGe btku5b LwdV0e FR7ZSc OJeuxf" data-hveid="CAkQAQ" data-ved="2ahUKEwj6mPnQ8_qQAxUccWwGHbRUE9AQ3fYKegQICRAB" jsaction="KjsqPd" jsname="HtgYJd" role="button" style="display: inline-block; vertical-align: middle; cursor: pointer; outline: 0px; -webkit-tap-highlight-color: transparent; color: rgb(28, 65, 154);" tabindex="0"><div class="niO4u" style="display: flex; justify-content: center; position: relative; align-items: center; width: 28px; z-index: 0; box-sizing: border-box; border-radius: 9999px; padding: 0px; border: 1px solid transparent; background: transparent; height: 20px; margin: 0px auto; min-height: 20px;"><span class="TwMgNb Hkv2Pe" style="color: rgb(31, 31, 31) !important; background: unset !important; display: flex; align-items: center;"><span class="iPjmzb Sorfoc gNGSDf" style="display: flex; height: unset; rotate: 135deg;"><span class="z1asCe Sb7k4e" style="display: inline-block; fill: currentcolor; height: 18px; line-height: 18px; position: relative; width: 18px;"><svg aria-hidden="true" focusable="false" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></span></span></div></div></div></div></div></div><div class="WaaZC" id="bkmrk-rabbitmq%3A" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CAIQAQ" data-ved="2ahUKEwj6mPnQ8_qQAxUccWwGHbRUE9AQo_EKegQIAhAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="7285565964511541576">RabbitMQ:</span></div></div></div><div class="WaaZC" id="bkmrk-rabbitmq-is-a-genera" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc uP58nb MNX06c" data-hveid="CAYQAQ" data-ved="2ahUKEwj6mPnQ8_qQAxUccWwGHbRUE9AQo_EKegQIBhAB" style="margin: 10px 0px; font-size: 16px; font-weight: normal; line-height: 24px; letter-spacing: normal;"><span data-huuid="7285565964511541882">RabbitMQ is a general-purpose message broker that implements the Advanced Message Queuing Protocol (AMQP). </span><span data-huuid="7285565964511542035">It excels in scenarios requiring complex message routing, message prioritization, and reliable delivery.</span></div></div></div><div class="WaaZC" id="bkmrk-key-features%3A-flexib" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <span data-huuid="7285565964511542494">**Key Features:**</span>
    - <span data-huuid="7285565964511542953">**Flexible Routing:** </span><span data-huuid="7285565964511543106">Supports various exchange types (direct, fanout, topic, headers) for sophisticated message routing based on routing keys or message headers.</span>
    - <span data-huuid="7285565964511539316">**Message Persistence:** </span><span data-huuid="7285565964511539469">Offers message persistence to disk, ensuring messages are not lost even if the broker crashes.</span>
    - <span data-huuid="7285565964511539775">**Message Acknowledgements:** </span><span data-huuid="7285565964511539928">Consumers explicitly acknowledge message processing, providing reliable delivery guarantees.</span>
    - <span data-huuid="7285565964511540234">**Dead Letter Exchanges (DLX):** </span><span data-huuid="7285565964511540387">Allows for handling undeliverable messages by routing them to a designated DLX.</span>
    - <span data-huuid="7285565964511540693">**Plugins:** </span><span data-huuid="7285565964511540846">Extensible with various plugins for features like MQTT, STOMP, and management UI.</span>

</div></div><div class="WaaZC" id="bkmrk-apache-kafka%3A" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CCQQAQ" data-ved="2ahUKEwj6mPnQ8_qQAxUccWwGHbRUE9AQo_EKegQIJBAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="4434816904309870078">Apache Kafka:</span></div></div></div><div class="WaaZC" id="bkmrk-kafka-is-a-distribut" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc uP58nb MNX06c" data-hveid="CCYQAQ" data-ved="2ahUKEwj6mPnQ8_qQAxUccWwGHbRUE9AQo_EKegQIJhAB" style="margin: 10px 0px; font-size: 16px; font-weight: normal; line-height: 24px; letter-spacing: normal;"><span data-huuid="4434816904309868632">Kafka is a distributed event streaming platform designed for high-throughput, fault-tolerant, and real-time data streaming. </span><span data-huuid="4434816904309867909">It is optimized for handling massive volumes of data and enabling stream processing applications.</span></div></div></div><div class="WaaZC" id="bkmrk-key-features%3A-distri" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <span data-huuid="4434816904309869836">**Key Features:**</span>
    - <span data-huuid="4434816904309867667">**Distributed Commit Log:** </span><span data-huuid="4434816904309866944">Stores messages in topics, which are partitioned and replicated across a cluster of brokers.</span>
    - <span data-huuid="4434816904309869594">**High Throughput:** </span><span data-huuid="4434816904309868871">Designed for processing billions of messages per second, making it suitable for large-scale data pipelines.</span>
    - <span data-huuid="4434816904309867425">**Message Retention:** </span><span data-huuid="4434816904309866702">Messages are retained in topics for a configurable period, allowing consumers to replay messages or process them at their own pace.</span>
    - <span data-huuid="4434816904309869352">**Scalability:** </span><span data-huuid="4434816904309868629">Easily scales horizontally by adding more brokers and partitions.</span>
    - <span data-huuid="4434816904309867183">**Stream Processing:** </span><span data-huuid="4434816904309870556">Provides APIs (Kafka Streams) for building real-time stream processing applications.</span>

</div></div><div class="WaaZC" id="bkmrk-choosing-between-rab" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CD8QAQ" data-ved="2ahUKEwj6mPnQ8_qQAxUccWwGHbRUE9AQo_EKegQIPxAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="6577113493012979629">Choosing between RabbitMQ and Kafka:</span></div></div></div><div class="WaaZC" id="bkmrk-rabbitmq-is-generall" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 0px; border-bottom: none; margin-inline-start: -20px;"><div class="GmFi7" data-crb-p="" style="display: flex; width: 631.781px;"><div><div data-ivep="true" data-vpload="" jsaction="PdWSXe:h5M12e;rcuQ6b:npT2md;" jscontroller="LdB9sd" jsdata="X2sNs;_;fPsbafrqFZziseMPtKnNgA06" jsmodel="Wn3aEc" jsshadow=""><div jsslot=""><div class="hUqmeb ivg-i" data-hveid="CFwQBA" data-ved="2ahUKEwj6mPnQ8_qQAxUccWwGHbRUE9AQoucNegQIXBAE" jsaction="trigger.PdWSXe" style="cursor: pointer;"><div class="rGAJof q1MG4e mNsIhb" style="height: 87.9937px; border-radius: 8px; overflow: hidden;">  
    </div></div></div></div></div><div class="xFTqob B4fN8b" style="flex: 1 1 0%; min-width: 0px; margin-inline-start: 12px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1);"><span data-huuid="6577113493012978324">**RabbitMQ**</span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 14px; line-height: 20px;"><span data-huuid="6577113493012977889">is generally preferred for:</span>
    - <span data-huuid="6577113493012976584">**Low-latency, reliable message delivery**: </span><span data-huuid="6577113493012976149">with complex routing requirements.</span>
    - <span data-huuid="6577113493012979375">**Task queues**: </span><span data-huuid="6577113493012978940">and background job processing.</span>
    - <span data-huuid="6577113493012978070">**Inter-service communication**: </span><span data-huuid="6577113493012977635">in microservices architectures where individual message delivery is critical.</span>
    
    </div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none; margin-inline-start: -20px;"><div class="GmFi7" data-crb-p="" style="display: flex; width: 631.781px;"><div><div data-ivep="true" data-vpload="" jsaction="PdWSXe:h5M12e;rcuQ6b:npT2md;" jscontroller="LdB9sd" jsdata="X2sNs;_;fPsbafrqFZziseMPtKnNgA05" jsmodel="Wn3aEc" jsshadow=""><div jsslot=""><div class="hUqmeb ivg-i" data-hveid="CFoQBA" data-ved="2ahUKEwj6mPnQ8_qQAxUccWwGHbRUE9AQoucNegQIWhAE" jsaction="trigger.PdWSXe" style="cursor: pointer;"><div class="rGAJof q1MG4e mNsIhb" style="height: 87.9937px; border-radius: 8px; overflow: hidden;">  
    </div></div></div></div></div><div class="xFTqob B4fN8b" style="flex: 1 1 0%; min-width: 0px; margin-inline-start: 12px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1);"><span data-huuid="6577113493012976765">**Kafka**</span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 14px; line-height: 20px;"><span data-huuid="6577113493012976330">is generally preferred for:</span>
    - <span data-huuid="6577113493012979121">**High-volume, real-time data streaming**: </span><span data-huuid="6577113493012978686">and event sourcing.</span>
    - <span data-huuid="6577113493012977816">**Building data pipelines**: </span><span data-huuid="6577113493012977381">and integrating various data sources.</span>
    - <span data-huuid="6577113493012976511">**Stream processing applications**: </span><span data-huuid="6577113493012976076">that require analyzing and transforming data in real-time.</span>
    - <span data-huuid="6577113493012979302">**Log aggregation**: </span><span data-huuid="6577113493012978867">and monitoring.</span>
    
    </div></div></div></div>

</div></div>

# Message queues (RabbitMQ, Kafka) in nodejs

<div class="WaaZC" id="bkmrk-ntegrating-message-q" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc" data-hveid="CAYQAQ" data-ved="2ahUKEwiw5om49PqQAxXaSGwGHc1cFDwQo_EKegQIBhAB" style="margin: 0px 0px 10px;"><span data-huuid="7082521633215866347">ntegrating message queues like RabbitMQ and Apache Kafka into Node.js applications enables building robust, scalable, and asynchronous systems, particularly beneficial in microservice architectures.</span></div></div></div><div class="WaaZC" id="bkmrk-rabbitmq-in-node.js%3A" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CAgQAQ" data-ved="2ahUKEwiw5om49PqQAxXaSGwGHc1cFDwQo_EKegQICBAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="7082521633215864961">RabbitMQ in Node.js:</span></div></div></div><div class="WaaZC" id="bkmrk-rabbitmq-is-a-popula" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc" data-hveid="CAoQAQ" data-ved="2ahUKEwiw5om49PqQAxXaSGwGHc1cFDwQo_EKegQIChAB" style="margin: 10px 0px;"><span data-huuid="7082521633215867671">RabbitMQ is a popular open-source message broker that implements the Advanced Message Queuing Protocol (AMQP). </span><span data-huuid="7082521633215864930">It excels in scenarios requiring complex routing, message guarantees, and diverse messaging patterns like point-to-point, publish/subscribe, and request/reply.</span></div></div></div><div class="WaaZC" id="bkmrk-key-concepts-and-usa" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CAcQAQ" data-ved="2ahUKEwiw5om49PqQAxXaSGwGHc1cFDwQo_EKegQIBxAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="7082521633215867640">Key Concepts and Usage:</span></div></div></div><div class="WaaZC" id="bkmrk-amqplib%C2%A0library%3A%C2%A0the" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <span data-huuid="7082521633215867609">`amqplib` library: </span><span data-huuid="7082521633215864868">The primary library for interacting with RabbitMQ in Node.js.</span>
- <span data-huuid="7082521633215867578">**Connection and Channel:** </span><span data-huuid="7082521633215864837">Establish a connection to the RabbitMQ server and create a channel for communication.</span>
- <span data-huuid="7082521633215867547">**Queues:** </span><span data-huuid="7082521633215868902">Declare and manage queues where messages are stored.</span>
- <span data-huuid="7082521633215867516">**Producers:** </span><span data-huuid="7082521633215868871">Send messages to queues.</span>
- <span data-huuid="7082521633215867485">**Consumers:** </span><span data-huuid="7082521633215868840">Receive and process messages from queues.</span>
- <span data-huuid="7082521633215867454">**Exchanges:** </span><span data-huuid="7082521633215868809">Route messages to queues based on specific rules (e.g., direct, fanout, topic).</span>
- <span data-huuid="7082521633215867423">**Acknowledgments:** </span><span data-huuid="7082521633215868778">Consumers acknowledge message receipt to ensure reliable delivery.</span>

</div></div><div class="WaaZC" id="bkmrk-example-%28producer%29%3A" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CCkQAQ" data-ved="2ahUKEwiw5om49PqQAxXaSGwGHc1cFDwQo_EKegQIKRAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="13315972262720195749">Example (Producer):</span></div></div></div><div class="WaaZC" id="bkmrk-javascript" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc" style="border-image: none 100% / 1 / 0 stretch; border-radius: 8px; font-size: 14px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); margin-bottom: 20px; color: rgb(10, 10, 10); border: 1.2px solid rgb(169, 172, 170);"><div class="zYSUYd" style="display: flex; flex-direction: row; overflow: hidden; border-radius: 8px 8px 0px 0px;"><div class="FS7GEb" style="display: flex; flex-direction: column; flex-grow: 1; min-width: 38%; width: 629.381px;"><div class="dDrxod" style="height: 34px; display: flex; justify-content: space-between; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border-bottom: 1.2px solid rgb(169, 172, 170);"><div class="x7ndcb" style="padding-left: 16px; display: flex; align-items: center; color: rgb(10, 10, 10);">JavaScript</div><div aria-live="polite" class="WDoJJe" style="margin-right: 4px; display: flex; align-items: center;"><button aria-label="Copy code to clipboard" class="hqI3tf B4zsNc" data-ved="2ahUKEwiw5om49PqQAxXaSGwGHc1cFDwQ9MILegQIJxAB" role="button" style="margin: 0px 2px; background: none; height: 34px; border: none; color: rgb(5, 40, 97); position: relative; top: 2px; outline: 0px;" tabindex="0" title="Copy"><span class="z1asCe wm4nBd" style="display: inline-block; fill: currentcolor; height: 20px; line-height: 20px; position: relative; width: 20px;"><svg aria-hidden="true" enable-background="new 0 0 24 24" focusable="false" height="24" viewbox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><g><rect fill="none" height="24" width="24"></rect></g><g><path d="M16,20H5V6H3v14c0,1.1,0.9,2,2,2h11V20z M20,16V4c0-1.1-0.9-2-2-2H9C7.9,2,7,2.9,7,4v12c0,1.1,0.9,2,2,2h9 C19.1,18,20,17.1,20,16z M18,16H9V4h9V16z"></path></g></svg></span></button></div></div></div></div><div class="QQjpRc" style="display: flex; flex-direction: row; overflow: hidden; border-radius: 0px 0px 8px 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5);"><div class="FS7GEb" jsname="zEXxAd" style="display: flex; flex-direction: column; flex-grow: 1; min-width: 38%; width: 629.381px;"></div></div></div></div></div></div>```
const amqp = require('amqplib');

async function sendToQueue(queueName, message) {
  const connection = await amqp.connect('amqp://localhost');
  const channel = await connection.createChannel();
  await channel.assertQueue(queueName, { durable: false }); // durable: false means queue is deleted when server restarts
  channel.sendToQueue(queueName, Buffer.from(message));
  console.log(`Sent: '${message}' to queue '${queueName}'`);
  setTimeout(() => {
    connection.close();
  }, 500);
}

sendToQueue('myQueue', 'Hello RabbitMQ!');
```

<div class="WaaZC" id="bkmrk-kafka-in-node.js%3A" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CC0QAQ" data-ved="2ahUKEwiw5om49PqQAxXaSGwGHc1cFDwQo_EKegQILRAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="12242046223910488543">Kafka in Node.js:</span></div></div></div><div class="WaaZC" id="bkmrk-apache-kafka-is-a-di" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc" data-hveid="CC8QAQ" data-ved="2ahUKEwiw5om49PqQAxXaSGwGHc1cFDwQo_EKegQILxAB" style="margin: 10px 0px;"><span data-huuid="12242046223910488449">Apache Kafka is a distributed streaming platform designed for high-throughput, low-latency data streams. </span><span data-huuid="12242046223910486354">It's ideal for log aggregation, real-time analytics, and event-driven architectures where data retention and stream processing are crucial.</span></div></div></div><div class="WaaZC" id="bkmrk-key-concepts-and-usa-1" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CDQQAQ" data-ved="2ahUKEwiw5om49PqQAxXaSGwGHc1cFDwQo_EKegQINBAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="788306795785912550">Key Concepts and Usage:</span></div></div></div><div class="WaaZC" id="bkmrk-kafka-node%C2%A0or%C2%A0node-r" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <span data-huuid="788306795785914701">`kafka-node` or `node-rdkafka` libraries: </span><span data-huuid="788306795785915418">Popular clients for Node.js. </span><span data-huuid="788306795785916135">`node-rdkafka` is often preferred for performance due as it's a binding to `librdkafka` (a C library).</span>
- <span data-huuid="788306795785913473">**Topics:** </span><span data-huuid="788306795785914190">Messages are organized into topics.</span>
- <span data-huuid="788306795785915624">**Producers:** </span><span data-huuid="788306795785916341">Publish messages to topics.</span>
- <span data-huuid="788306795785913679">**Consumers and Consumer Groups:** </span><span data-huuid="788306795785914396">Subscribe to topics and process messages. </span><span data-huuid="788306795785915113">Consumer groups enable parallel consumption and fault tolerance.</span>
- <span data-huuid="788306795785912451">**Partitions:** </span><span data-huuid="788306795785913168">Topics are divided into partitions for scalability and parallelism.</span>
- <span data-huuid="788306795785914602">**Offsets:** </span><span data-huuid="788306795785915319">Consumers track their position within a partition using offsets.</span>

</div></div><div class="WaaZC" id="bkmrk-example-%28producer-us" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: 700ms cubic-bezier(0.2, 0, 0, 1) 200ms 1 normal backwards running response-text-colorshift, 400ms cubic-bezier(0, 0, 0.2, 1) 83ms 1 normal backwards running response-text-fadein; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CE4QAQ" data-ved="2ahUKEwiw5om49PqQAxXaSGwGHc1cFDwQo_EKegQIThAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="6562282184043991589">Example (Producer using `kafka-node`):</span></div></div></div><div class="WaaZC" id="bkmrk-javascript-1" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: 700ms cubic-bezier(0.2, 0, 0, 1) 200ms 1 normal backwards running response-text-colorshift, 400ms cubic-bezier(0, 0, 0.2, 1) 83ms 1 normal backwards running response-text-fadein; color: rgb(10, 10, 10);"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc" style="border-image: none 100% / 1 / 0 stretch; border-radius: 8px; font-size: 14px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); margin-bottom: 20px; color: rgb(10, 10, 10); border: 1.2px solid rgb(169, 172, 170);"><div class="zYSUYd" style="display: flex; flex-direction: row; overflow: hidden; border-radius: 8px 8px 0px 0px;"><div class="FS7GEb" style="display: flex; flex-direction: column; flex-grow: 1; min-width: 38%; width: 629.381px;"><div class="dDrxod" style="height: 34px; display: flex; justify-content: space-between; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border-bottom: 1.2px solid rgb(169, 172, 170);"><div class="x7ndcb" style="padding-left: 16px; display: flex; align-items: center; color: rgb(10, 10, 10);">JavaScript</div><div aria-live="polite" class="WDoJJe" style="margin-right: 4px; display: flex; align-items: center;"><button aria-label="Copy code to clipboard" class="hqI3tf B4zsNc" data-ved="2ahUKEwiw5om49PqQAxXaSGwGHc1cFDwQ9MILegQITBAB" role="button" style="margin: 0px 2px; background: none; height: 34px; border: none; color: rgb(5, 40, 97); position: relative; top: 2px; outline: 0px;" tabindex="0" title="Copy"><span class="z1asCe wm4nBd" style="display: inline-block; fill: currentcolor; height: 20px; line-height: 20px; position: relative; width: 20px;"><svg aria-hidden="true" enable-background="new 0 0 24 24" focusable="false" height="24" viewbox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><g><rect fill="none" height="24" width="24"></rect></g><g><path d="M16,20H5V6H3v14c0,1.1,0.9,2,2,2h11V20z M20,16V4c0-1.1-0.9-2-2-2H9C7.9,2,7,2.9,7,4v12c0,1.1,0.9,2,2,2h9 C19.1,18,20,17.1,20,16z M18,16H9V4h9V16z"></path></g></svg></span></button></div></div></div></div><div class="QQjpRc" style="display: flex; flex-direction: row; overflow: hidden; border-radius: 0px 0px 8px 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5);"><div class="FS7GEb" jsname="zEXxAd" style="display: flex; flex-direction: column; flex-grow: 1; min-width: 38%; width: 629.381px;"></div></div></div></div></div></div>```
const kafka = require('kafka-node');
const Producer = kafka.Producer;
const Client = kafka.KafkaClient;

const client = new Client({ kafkaHost: 'localhost:9092' });
const producer = new Producer(client);

producer.on('ready', () => {
  const payloads = [
    { topic: 'myTopic', messages: 'Hello Kafka!' },
  ];
  producer.send(payloads, (err, data) => {
    if (err) console.error(err);
    else console.log('Sent:', data);
    client.close();
  });
});

producer.on('error', (err) => {
  console.error('Producer error:', err);
});
```

<div class="WaaZC" id="bkmrk-choosing-between-rab" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: 700ms cubic-bezier(0.2, 0, 0, 1) 200ms 1 normal backwards running response-text-colorshift, 400ms cubic-bezier(0, 0, 0.2, 1) 83ms 1 normal backwards running response-text-fadein; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CFIQAQ" data-ved="2ahUKEwiw5om49PqQAxXaSGwGHc1cFDwQo_EKegQIUhAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="8194448187071131726">Choosing between RabbitMQ and Kafka:</span></div></div></div><div class="WaaZC" id="bkmrk-rabbitmq%3A%C2%A0-suited-fo" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: 700ms cubic-bezier(0.2, 0, 0, 1) 200ms 1 normal backwards running response-text-colorshift, 400ms cubic-bezier(0, 0, 0.2, 1) 83ms 1 normal backwards running response-text-fadein; color: rgb(10, 10, 10);">- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 0px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="8194448187071131947">**RabbitMQ:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="8194448187071133386">Suited for traditional message queuing, task queues, complex routing, and scenarios requiring strong message guarantees and per-message processing.</span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="8194448187071132168">**Kafka:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="8194448187071133607">Ideal for high-volume data streams, event sourcing, real-time analytics, and scenarios where message retention and replayability are important</span></div></div></div></div>

</div></div>

# Message queues (RabbitMQ, Kafka) in laravel

<div class="WaaZC" id="bkmrk-integrating-rabbitmq" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc" data-hveid="CAYQAQ" data-ved="2ahUKEwii-9fl9PqQAxWfw6ACHZNOL5AQo_EKegQIBhAB" style="margin: 0px 0px 10px;"><span data-huuid="9160497411233952207">Integrating RabbitMQ or Kafka with Laravel involves utilizing Laravel's queue system to leverage these powerful message brokers for asynchronous task processing and inter-service communication.</span></div></div></div><div class="WaaZC" id="bkmrk-rabbitmq-in-laravel%3A" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CAUQAQ" data-ved="2ahUKEwii-9fl9PqQAxWfw6ACHZNOL5AQo_EKegQIBRAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="9160497411233951945">RabbitMQ in Laravel:</span></div></div></div><div class="WaaZC" id="bkmrk-installation%3A%C2%A0since-" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <span data-huuid="9160497411233953600">**Installation:** </span><span data-huuid="9160497411233955517">Since Laravel does not natively support RabbitMQ, a third-party package like `vladimir-yuldashev/laravel-queue-rabbitmq` is required.<span class="pjBG2e" data-cid="f265a4d7-9b32-401d-9f33-e74f98e1a157"><span class="UV3uM" style="white-space: nowrap;"> </span></span></span><div class="NPrrbc" data-cid="f265a4d7-9b32-401d-9f33-e74f98e1a157" data-uuids="9160497411233953600,9160497411233955517" style="margin-inline-end: 6px; vertical-align: middle; display: inline-flex;"><div aria-label="View related links" class="BMebGe btku5b LwdV0e FR7ZSc OJeuxf" data-hveid="CAkQAQ" data-ved="2ahUKEwii-9fl9PqQAxWfw6ACHZNOL5AQ3fYKegQICRAB" jsaction="KjsqPd" jsname="HtgYJd" role="button" style="display: inline-block; vertical-align: middle; cursor: pointer; outline: 0px; -webkit-tap-highlight-color: transparent; color: rgb(28, 65, 154);" tabindex="0"><div class="niO4u" style="display: flex; justify-content: center; position: relative; align-items: center; width: 28px; z-index: 0; box-sizing: border-box; border-radius: 9999px; padding: 0px; border: 1px solid transparent; background: transparent; height: 20px; margin: 0px auto; min-height: 20px;"><span class="TwMgNb Hkv2Pe" style="color: rgb(31, 31, 31) !important; background: unset !important; display: flex; align-items: center;"><span class="iPjmzb Sorfoc gNGSDf" style="display: flex; height: unset; rotate: 135deg;"><span class="z1asCe Sb7k4e" style="display: inline-block; fill: currentcolor; height: 18px; line-height: 18px; position: relative; width: 18px;"><svg aria-hidden="true" focusable="false" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z"></path></svg></span></span></span></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-code" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div jsaction="rcuQ6b:npT2md" jscontroller="JegcYe"><div class="ecCNFc" style="border-image: none 100% / 1 / 0 stretch; border-radius: 8px; font-size: 14px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5); margin-bottom: 20px; color: rgb(10, 10, 10); border: 1.2px solid rgb(169, 172, 170);"><div class="zYSUYd" style="display: flex; flex-direction: row; overflow: hidden; border-radius: 8px 8px 0px 0px;"><div class="FS7GEb" style="display: flex; flex-direction: column; flex-grow: 1; min-width: 38%; width: 629.381px;"><div class="dDrxod" style="height: 34px; display: flex; justify-content: space-between; align-items: center; background: none 0% 0% / auto repeat scroll padding-box border-box rgb(229, 237, 255); border-bottom: 1.2px solid rgb(169, 172, 170);"><div class="x7ndcb" style="padding-left: 16px; display: flex; align-items: center; color: rgb(10, 10, 10);">Code</div><div aria-live="polite" class="WDoJJe" style="margin-right: 4px; display: flex; align-items: center;"><button aria-label="Copy code to clipboard" class="hqI3tf B4zsNc" data-ved="2ahUKEwii-9fl9PqQAxWfw6ACHZNOL5AQ9MILegQIAhAB" role="button" style="margin: 0px 2px; background: none; height: 34px; border: none; color: rgb(5, 40, 97); position: relative; top: 2px; outline: 0px;" tabindex="0" title="Copy"><span class="z1asCe wm4nBd" style="display: inline-block; fill: currentcolor; height: 20px; line-height: 20px; position: relative; width: 20px;"><svg aria-hidden="true" enable-background="new 0 0 24 24" focusable="false" height="24" viewbox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><g><rect fill="none" height="24" width="24"></rect></g><g><path d="M16,20H5V6H3v14c0,1.1,0.9,2,2,2h11V20z M20,16V4c0-1.1-0.9-2-2-2H9C7.9,2,7,2.9,7,4v12c0,1.1,0.9,2,2,2h9 C19.1,18,20,17.1,20,16z M18,16H9V4h9V16z"></path></g></svg></span></button></div></div></div></div><div class="QQjpRc" style="display: flex; flex-direction: row; overflow: hidden; border-radius: 0px 0px 8px 8px; background: none 0% 0% / auto repeat scroll padding-box border-box rgba(245, 248, 255, 0.5);"><div class="FS7GEb" jsname="zEXxAd" style="display: flex; flex-direction: column; flex-grow: 1; min-width: 38%; width: 629.381px;"></div></div></div></div></div></div>```
    composer require vladimir-yuldashev/laravel-queue-rabbitmq
```

<div class="WaaZC" id="bkmrk-configuration%3A-add-r" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 0px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="9160497411233952814">**Configuration:**</span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;">
    - <span data-huuid="9160497411233954469">Add RabbitMQ connection details to `config/queue.php`, specifying the driver, host, port, user, password, virtual host, and queue name.</span>
    - <span data-huuid="9160497411233954207">Set corresponding environment variables in your `.env` file (e.g., `RABBITMQ_HOST`, `RABBITMQ_PORT`).</span>
    
    </div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="9160497411233953945">**Job Creation and Dispatching:**</span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;">
    - <span data-huuid="9160497411233955600">Create Laravel jobs using `php artisan make:job YourJobName`.</span>
    - <span data-huuid="9160497411233955338">Dispatch jobs to the RabbitMQ queue using `dispatch(new YourJobName())->onQueue('your_rabbitmq_queue_name');`.</span>
    
    </div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="9160497411233955076">**Consumption:**</span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;">
    - <span data-huuid="9160497411233952635">Run the Laravel queue worker to consume messages from the RabbitMQ queue: `php artisan queue:work rabbitmq --queue=your_rabbitmq_queue_name`.</span>
    - <span data-huuid="9160497411233952373">For continuous consumption, consider using Laravel Horizon or a process manager like Supervisor.</span>
    
    </div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-kafka-in-laravel%3A" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CCsQAQ" data-ved="2ahUKEwii-9fl9PqQAxWfw6ACHZNOL5AQo_EKegQIKxAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="9607783949532631359">Kafka in Laravel:</span></div></div></div><div class="WaaZC" id="bkmrk-integrating-kafka-wi" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div class="rPeykc uP58nb MNX06c" data-hveid="CCoQAQ" data-ved="2ahUKEwii-9fl9PqQAxWfw6ACHZNOL5AQo_EKegQIKhAB" style="margin: 10px 0px; font-size: 16px; font-weight: normal; line-height: 24px; letter-spacing: normal;"><span data-huuid="9607783949532634681"><span aria-level="2" role="heading">Integrating Kafka with Laravel typically involves using a PHP Kafka client library, as there isn't a direct queue driver like for RabbitMQ.</span></span></div></div></div><div class="WaaZC" id="bkmrk-installation%3A%C2%A0-insta" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 0px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="9607783949532631472">**Installation:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="9607783949532633133">Install a PHP Kafka client library (e.g., `php-rdkafka` extension or a Composer package like `enqueue/kafka`).</span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="9607783949532632359">**Producer Setup:**</span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;">
    - <span data-huuid="9607783949532633246">Configure the Kafka producer with broker addresses and other settings.</span>
    - <span data-huuid="9607783949532632472">Create a service or class responsible for producing messages and publishing them to Kafka topics.</span>
    
    </div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="9607783949532631698">**Consumer Setup:**</span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;">
    - <span data-huuid="9607783949532632585">Configure the Kafka consumer with broker addresses, consumer group ID, and topics to subscribe to.</span>
    - <span data-huuid="9607783949532631811">Implement a consumer process (e.g., a custom Artisan command or a dedicated service) that continuously polls for messages from Kafka topics and processes them within your Laravel application.</span>
    
    </div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="9607783949532635133">**Message Handling:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="9607783949532632698">Within your Kafka consumer, you can dispatch Laravel jobs to handle the received messages, leveraging Laravel's job processing capabilities.</span></div></div></div></div>

</div></div><div class="WaaZC" id="bkmrk-key-considerations%3A" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);"><div aria-level="3" class="rPeykc pyPiTc" data-hveid="CEQQAQ" data-ved="2ahUKEwii-9fl9PqQAxWfw6ACHZNOL5AQo_EKegQIRBAB" role="heading" style="margin: 20px 0px 10px; font-size: 20px; font-weight: 600; line-height: 28px;"><span data-huuid="15555906343834102683">Key Considerations:</span></div></div></div><div class="WaaZC" id="bkmrk-choice-of-broker%3A%C2%A0-r" style="color: rgb(10, 10, 10); font-family: 'Google Sans', Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="RJPOee EIJn2" style="animation: auto ease 0s 1 normal none running none !important; color: rgb(10, 10, 10);">- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 0px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="15555906343834102694">**Choice of Broker:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="15555906343834099967">RabbitMQ is a traditional message broker ideal for reliable message delivery and complex routing, while Kafka is a distributed streaming platform designed for high-throughput, real-time data pipelines and stream processing. </span><span data-huuid="15555906343834101336">The choice depends on your specific use case.</span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="15555906343834099978">**Error Handling and Retries:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="15555906343834101347">Implement robust error handling and message retry mechanisms to ensure message delivery and processing even in case of failures.</span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="15555906343834099989">**Scalability:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="15555906343834101358">Both RabbitMQ and Kafka offer excellent scalability, but their architectural approaches differ. </span><span data-huuid="15555906343834102727">Plan your setup to accommodate your expected message volumes and processing requirements.</span></div></div></div></div>
- <div class="zMgcWd dSKvsb" data-il="" style="padding-bottom: 0px; padding-top: 8px; border-bottom: none;"><div data-crb-p=""><div class="xFTqob" style="flex: 1 1 0%; min-width: 0px;"><div class="Gur8Ad" style="font-size: 16px; font-weight: 500; line-height: 24px; overflow: hidden; padding-bottom: 4px; transition: transform 200ms cubic-bezier(0.2, 0, 0, 1); display: inline;"><span data-huuid="15555906343834101369">**Monitoring:** </span></div><div class="vM0jzc" style="color: rgb(10, 10, 10); font-size: 16px; line-height: 24px; display: inline;"><span data-huuid="15555906343834102738">Monitor your message queues and consumers to ensure smooth operation and identify potential bottleneck</span></div></div></div></div>

</div></div>