Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between event queue and message queue

I was just seeing the documentation of three methods which can be used to execute a piece of code in the UI thread while we are working in a worker thread. The methods are:

  1. public final void runOnUIThread(Runnable action) - Runs the specified action on the UI thread. If the current thread is the UI thread, then the action is executed immediately. If the current thread is not the UI thread, the action is posted to the event queue of the UI thread

  2. public boolean post(Runnable action) - Causes the Runnable to be added to the message queue. The runnable will be run on the user interface thread.

  3. public boolean postDelayed(Runnable action, long delayMillis) - Causes the Runnable to be added to the message queue, to be run after the specified amount of time elapses. The runnable will be run on the user interface thread.

The first one posts the Runnable to the event queue of the UI thread, while the other two add the Runnable to the message queue. Please tell me the difference between the two?

My web search tell me that an event queue is simply a queue of events waiting to be executed by the thread. I am not clear about the message queue. MessageQueue is some class as well, is this related to that?

Thank you in advance.

like image 290
Solace Avatar asked Mar 28 '14 12:03

Solace


People also ask

What is the difference between event and message?

The difference between events and messages is that events are used for intra-stack communication, whereas messages are used for inter-stack communication.

What is the difference between message queues vs event streaming platforms?

Once messages are written to a stream, they stay there. Conversely, with message queues or message buses, a message is removed from a queue and then passed to a service's consumer.

What is the difference between event driven and message driven?

Events are messages As discussed above, in Message Driven systems, each component send items to a fixed recipient. In Event Driven systems, on the other hand, each component produces items of data with a fixed sender and shares them with any consumer.

What is an event queue?

An event queue is a repository where events from an application are held prior to being processed by a receiving program or system. Event queues are often used in the context of an enterprise messaging system.

What is the difference between a queue and an event?

This means that the messages in the queue are actually commands, which is suited towards imperative programming, and not an event, which is suited towards reactive programming. With queues, you generally execute the same logic in the same domain for every message on the queue

What is the difference between an EventQueue and a messagequeue?

With an EventQueue this is not necessary. So message managing gives more control to the sender of the message. With an event queue all the sender can do is throw a request in the queue and hope for the best. That additional control provided by a MessageQueue comes with a small complexity penalty.

What is a message queue and how does it work?

In essence, instead of having an Event result in a service yelling to a group of interested parties “something happened!”, a Message Queue takes an event or output that requires additional processing and adds it to a long queue.

What is queueing in Salesforce?

Queues usually allow for some level of transaction when pulling a message off, to ensure that the desired action was executed, before the message gets removed. Not all queueing systems have the same functionality, but once a message has been processed, it gets removed from the queue.


2 Answers

A message queue and an event queue are very similar design patterns with one notable difference.

First off let's review the similarities. Both are asynchronous. They store notifications in FIFO order. Sending a notification enqueues the event/message and returns.

Later on the EventManager/MessageManager will dispatch all those Events/Messages to the recipient objects. The difference lies in that with MessageQueues it's typical that the sender requires a response. With an EventQueue this is not necessary.

So message managing gives more control to the sender of the message. With an event queue all the sender can do is throw a request in the queue and hope for the best. That additional control provided by a MessageQueue comes with a small complexity penalty.

Choose the simplest data structure that you need for the job.

like image 25
KeyC0de Avatar answered Sep 29 '22 03:09

KeyC0de


I think the two are synonymous. Events are indicated to the system using messages.

The real difference between the two methods is that one appends it to the queue immediately while the other delays it by the specified amount.

EDIT: More on messages

Messages are a way of communication between independent threads. In a way, it's a lot like the communication that takes place when you pull up a website in your browser: You send a message to the server detailing what exactly it is you want (GET www.stackoverflow.com, I will accept the following character encoding, do not track me, blablabla), which makes the server as the recipient of the message do something (retrieve content from the database, render the page, etc) and communicate the results of this back to you via a message.

How it works is like this: The thread has a Looper attached to it. All it does is run forever in a continuous loop, on each iteration checking whether there are any messages in its message queue. If there aren't, it goes to the next cycle. If there are, it retrieves the first message to deal with it.

However, the looper itself doesn't know what any of the messages mean - it's just there for looping. Neither does the thread, which just provides the infrastructure for the looper to run in. What the looper does know, however, is who to go to for handling the message: One of its Handlers. It passes the message to the handler, which can now go and do whatever it is that it needs to do to handle the message.

like image 74
BadIdeaException Avatar answered Sep 29 '22 03:09

BadIdeaException