Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Message queue

From Wikipedia, the free encyclopedia
Means of interprocess communication in software engineering
icon
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Message queue" – news ·newspapers ·books ·scholar ·JSTOR
(May 2009) (Learn how and when to remove this message)

Incomputer science,message queues andmailboxes aresoftware-engineeringcomponents typically used forinter-process communication (IPC), or for inter-thread communication within the same process. They use aqueue formessaging – the passing of control or of content.Group communication systems provide similar kinds of functionality.

The message queue paradigm is a sibling of thepublisher/subscriber pattern, and is typically one part of a largermessage-oriented middleware system. Most messaging systems support both the publisher/subscriber and message queue models in theirAPI, e.g.Java Message Service (JMS).

Competing Consumers pattern enables multiple concurrent consumers to process messages on the same message queue.[1]

Remit and ownership

[edit]

Message queues implement anasynchronous communication pattern between two or more processes/threads whereby the sending and receiving party do not need to interact with the message queue at the same time. Messages placed onto the queue are stored until the recipient retrieves them. Message queues have implicit or explicit limits on the size of data that may be transmitted in a single message and the number of messages that may remain outstanding on the queue.[2]

Remit

[edit]

Many implementations of message queues function internally within anoperating system or within anapplication. Such queues exist for the purposes of thatsystem only.[3][4][5]

Other implementations allow the passing of messages between different computer systems, potentially connecting multiple applications and multiple operating systems.[6] These message queuing systems typically provideresilience functionality to ensure that messages do not get "lost" in the event of a system failure. Examples of commercial implementations of this kind of message queuingsoftware (also known asmessage-oriented middleware) includeIBM MQ (formerly MQ Series) and Oracle Advanced Queuing (AQ). There is aJava standard calledJava Message Service, which has severalproprietary andfree software implementations.

Real-time operating systems (RTOSes) such asVxWorks andQNX encourage the use of message queuing as the primary inter-process or inter-thread communication mechanism. This can result in integration between message passing and CPU scheduling. Early examples of commercial RTOSes that encouraged a message-queue basis to inter-thread communication also includeVRTX andpSOS+, both of which date to the early 1980s. TheErlang programming language usesprocesses to provide concurrency; these processes communicate asynchronously using message queuing.

Ownership

[edit]

The message queue software can be either proprietary, open source or a mix of both. It is then run either on premise in private servers or on external cloud servers (message queuing service).

Examples on hardware-basedmessaging middleware vendors areSolace,Apigee, andIBM MQ.

Usage

[edit]

In a typical message-queueing implementation, asystem administrator installs and configures message-queueing software (aqueue manager or broker), and defines a named message queue. Or they register with amessage queuing service.

An application then registers a software routine that "listens" for messages placed onto the queue.

Second and subsequent applications may connect to the queue and transfer a message onto it.

The queue-manager software stores the messages until a receiving application connects and then calls the registered software routine. The receiving application then processes the message in an appropriate manner.

There are often numerous options as to the exact semantics of message passing, including:

  • Durability – messages may be kept in memory, written to disk, or even committed to aDBMS if the need for reliability indicates a more resource-intensive solution.
  • Security policies – which applications should have access to these messages?
  • Message purging policies – queues or messages may have a "time to live".
  • Message filtering – some systems support filtering data so that a subscriber may only see messages matching some pre-specified criteria of interest.
  • Delivery policies – do we need to guarantee that a message is delivered at least once, or no more than once?
  • Routing policies – in a system with many queue servers, what servers should receive a message or a queue's messages?
  • Batching policies – should messages be delivered immediately? Or should the system wait a bit and try to deliver many messages at once?
  • Queuing criteria – when should a message be considered "enqueued"? When one queue has it? Or when it has been forwarded to at least one remote queue? Or to all queues?
  • Receipt notification – A publisher may need to know when some or all subscribers have received a message.

These are all considerations that can have substantial effects on transaction semantics, system reliability, and system efficiency.

Standards and protocols

[edit]

Historically, message queuing has used proprietary, closed protocols, restricting the ability for different operating systems or programming languages to interact in a heterogeneous set of environments.

An early attempt to make message queuing more ubiquitous wasSun Microsystems'JMS specification, which provided aJava-only abstraction of a clientAPI. This allowed Java developers to switch between providers of message queuing in a fashion similar to that of developers usingSQL databases. In practice, given the diversity of message queuing techniques and scenarios, this wasn't always as practical as it could be.

Three standards have emerged which are used in open source message queue implementations:

  1. Advanced Message Queuing Protocol (AMQP) – feature-rich message queue protocol, approved as ISO/IEC 19464 since April 2014
  2. Streaming Text Oriented Messaging Protocol (STOMP) – simple, text-oriented message protocol
  3. MQTT (formerly MQ Telemetry Transport) – lightweight message queue protocol especially for embedded devices

These protocols are at different stages of standardization and adoption. The first two operate at the same level asHTTP, MQTT at the level ofTCP/IP.

Some proprietary implementations also use HTTP to provide message queuing by some implementations, such asAmazon'sSQS. This is because it is always possible to layer asynchronous behaviour (which is what is required for message queuing) over a synchronous protocol using request-response semantics. However, such implementations are constrained by the underlying protocol in this case and may not be able to offer the full fidelity or set of options required in message passing above.

Synchronous vs. asynchronous

[edit]

Many of the more widely knowncommunications protocols in use operatesynchronously. The HTTP protocol – used in theWorld Wide Web and inweb services – offers an obvious example where a user sends a request for a web page and then waits for a reply.

However, scenarios exist in which synchronous behaviour is not appropriate. For example,AJAX (AsynchronousJavaScript andXML) can be used to asynchronously send text, JSON or XML messages to update part of a web page with more relevant information.Google uses this approach for their Google Suggest, a search feature which sends the user's partially typed queries to Google's servers and returns a list of possible full queries the user might be interested in the process of typing. This list is asynchronously updated as the user types.

Other asynchronous examples exist in event notification systems andpublish/subscribe systems.

  • An application may need to notify another that an event has occurred, but does not need to wait for a response.
  • In publish/subscribe systems, an application "publishes" information for any number of clients to read.

In both of the above examples it would not make sense for the sender of the information to have to wait if, for example, one of the recipients had crashed.

Applications need not be exclusively synchronous or asynchronous. An interactive application may need to respond to certain parts of a request immediately (such as telling a customer that a sales request has been accepted, and handling the promise to draw on inventory), but may queue other parts (such as completing calculation of billing, forwarding data to the central accounting system, and calling on all sorts of other services) to be done some time later.

In all these sorts of situations, having a subsystem which performs message-queuing (or alternatively, a broadcast messaging system) can help improve the behavior of the overall system.

Implementation in UNIX

[edit]

There are two common message queue implementations inUNIX. One is part of the SYS V API, the other one is part ofPOSIX.

SYS V

[edit]

UNIX SYS V implements message passing by keeping an array of linked lists as message queues. Each message queue is identified by its index in the array, and has a unique descriptor. A given index can have multiple possible descriptors. UNIX gives standard functions to access the message passing feature.[7]

msgget()
This system call takes a key as an argument and returns a descriptor of the queue with the matching key if it exists. If it does not exist, and theIPC_CREAT flag is set, it makes a new message queue with the given key and returns its descriptor.
msgrcv()
Used to receive a message from a given queue descriptor. The caller process must have read permissions for the queue. It is of two types.[8]
  • Blocking receive puts the child to sleep if it cannot find a requested message type. It sleeps until another message is posted in the queue, and then wakes up to check again.
  • Non-blocking receive returns immediately to the caller, mentioning that it failed.
msgctl()
Used to change message queue parameters like the owner. Most importantly, it is used to delete the message queue by passing theIPC_RMID flag. A message queue can be deleted only by its creator, owner, or the superuser.

POSIX

[edit]

The POSIX.1-2001 message queue API is the later of the two UNIX message queue APIs. It is distinct from the SYS V API, but provides similar function. The unix man pagemq_overview(7) provides an overview of POSIX message queues.

Graphical user interfaces

[edit]

Graphical user interfaces (GUIs) employ a message queue, also called anevent queue orinput queue, to passgraphical input actions, such asmouse clicks, keyboard events, or other user inputs, to theapplication program.[9] The windowing system places messages indicating user or other events, such as timer ticks or messages sent by other threads, into the message queue. The GUI application removes these events one at a time by calling a routine calledgetNextEvent() or similar in anevent loop, and then calling the appropriate application routine to process that event.[10]

See also

[edit]

References

[edit]
  1. ^Gorton, Ian (2022).Foundations of Scalable Systems. O'Reilly Media.ISBN 9781098106034.
  2. ^Dive Into Queue Module In Python.Overview of POSIX message queues
  3. ^Win32 system message queues."About Messages and Message Queues".Windows User Interface. Microsoft Developer Network. Archived fromthe original on March 17, 2012. RetrievedApril 21, 2010.
  4. ^Linux and POSIX message queues.Overview of POSIX message queuesArchived 2012-05-04 at theWayback Machine at linux.die.net
  5. ^Using Linux Message Queues.Linux message queue functionsArchived 2012-04-08 at theWayback Machine at www.civilized.com
  6. ^For example, the MSMQ product."Message Queuing (MSMQ)".Network Communication. Microsoft Developer Network. RetrievedMay 9, 2009.
  7. ^Bach, M.J. (1986).The Design of the UNIX Operating System. Prentice-Hall.ISBN 9780132017992.
  8. ^Abraham Silberschatz, Peter B. Galvin (1994).Operating Systems Concepts. Addison-Wesley.ISBN 9780201504804.
  9. ^Cartwright, Corky."GUI Programming".Rice University:Robert (Corky) Cartwright. RetrievedJune 27, 2020.
  10. ^Nystrom, Robert (2014).Game Programming Patterns. Genever Benning.ISBN 978-0990582908. RetrievedJune 27, 2020.
Methods
Protocols
andstandards
Software libraries
andframeworks
Retrieved from "https://en.wikipedia.org/w/index.php?title=Message_queue&oldid=1334723988"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp