What is ActiveMQ used for - can we apply messaging concept using a Database?

前端 未结 8 671
花落未央
花落未央 2021-01-30 00:31

I looked it up and it used to send messages between 2 systems.
But why? Why wouldn\'t you just use a Database?
There must be some feature that ActiveM

8条回答
  •  别那么骄傲
    2021-01-30 01:22

    Consider the following generic user scenario

    USER SCENARIO

    • Customer uploads a text document
    • Your application converts the text document into a PDF
    • Your application emails the PDF back to the customer

    Database for a queue based system In this kind of circumstance, you might consider employing a database for your PDF job line. Regularly you'd make a database table that includes a line with records speaking to PDF demands. You'd at that point put a hail within the table speaking to which state the assignment is in and whether the errand is completed or not.

    INSERT INTO pdf_job_queue (name, status, email) VALUES ("White paper", "NEW", "myemail@example.com");
    
    SELECT * FROM pdf_job_queue WHERE queue = 'resize_queue' AND handled = false ORDER BY date_recived limit 1;
    

    You need to write code to insert the new requests into the database. Code that takes an input from the database, perhaps changes a status column, with values such as "NEW" and "PROCESSING", code that handles the request, more code that again updates the database status field to "FINISHED", and more code to remove the request from the queue.

    update pdf_job_queue set Status="FINISHED" where Id = 'SomeId';
    

    To operate effectively, you might need to poll the database quickly and frequently. Of course, this adds a significant load to the database and to your application.

    Message Queues When you try to achieve the same by using message queues.

    PUSHED IN REAL-TIME Messages from a message line are pushed in real-time rather than occasionally surveyed from a database. An altogether higher volume of concurrent messages can be upheld proficiently employing a message line. Messages in a message line are naturally cleaned up after being gotten.

    ACKNOWLEDGMENT An acknowledgment is sent back from the worker to tell the message queue that a particular message has been received and processed and that the message queue is free to delete it. If a worker dies without sending an acknowledgment, the message queue will understand that a message wasn't processed fully and will redeliver it to the queue and to another worker. That way you can be sure that no message is lost.

    For message queue systems I would always recommend ActiveMQ due to its easy installation, configuration, and very easy to scale.

提交回复
热议问题