Messages are posted to an exchange, which is often compared to a post office or mailbox. The exchange then distributes copies of the message to the queue using rules called bindings. The AMQP broker then passes the message to the consumer that subscribes to the queue or retrives the message from the queue as needed.
When publishing a message, publishers can specify various message properties (message metadata). Some of this metadata may be used by the broker, but others are completely opaque to the broker and are available only to the application receiving the message.
Networks are unreliable and applications may not be able to process messages, so the AMQP model has the concept of message validation: the consumer notifies the broker automatically when a message is delivered to the consumer, or whenever the application developer chooses to do so. When using message acknowledgement, the broker removes the message completely from the queue only when it is notified of the message (or group of messages).
For example, in some cases, when a message cannot be routed, it may be returned to the publisher or deleted, or put into a so-called Dead Letter queue if the broker implements an extension. Publishers choose how to handle this situation by publishing messages with certain parameters.
Queues, exchanges, and bindings are collectively referred to as AMQP entities.
A switch is an AMQP entity that sends messages. The switch takes the message and routes it to zero or more queues. The routing algorithm used depends on Exchange Types and rules known as Bindings. The AMQP 0-9-1 protocol provides four types of switching:
Direct exchange Fanout exchange Topic exchange Headers exchange Default Exchange Default Exchange Is a direct exchange of nameless (empty string) predeclared by the agent. It has a special property that makes it useful for simple applications: every Queue created is automatically bound to a switch whose Routing Key is the Queue Name.
Direct Exchange
Queues are bound to switches with Routing Key K.
When a new message with Routing Key R arrives at the direct exchange, if K = R, it is routed to the queue.
Direct exchanges are typically used to assign tasks in a circular manner among multiple workers (instances of the same application). When this is done, messages are load-balanced between consumers rather than between queues.
Fanout Exchange
Fanout Exchange delivers a copy of a message to each queue bound to it in the following scenarios:
Massively multiplayer online (MMO) games can be used for leaderboard updates or other global events.
Sports news sites can use Fanout Exchange to update ratings on mobile clients in real time.
Distributed systems can broadcast various status and configuration updates
Topic Exchange
Topic Exchanges should be considered whenever a problem involves multiple consumers/applications selectively choosing what type of messages they want to receive.
Example Uses:
Assign data related to a particular geographic location, such as point of sale
Background task processing is done by multiple workers, each capable of handling a specific set of tasks.
Stock price updates (and other types of financial data updates)
News updates that involve categorization or tagging (for example, specific sports or teams only)
Orchestration of different types of services in the cloud
Distributed architecture/OS-specific software builds or packages where each builder can handle only one architecture or operating system.
Headers Exchange
Multiple headers can be used to bind queues to head exchanges for matching purposes. In this case, the agent needs the application developer to provide a piece of information, namely, should it consider any header matching messages, or all header matching messages? This is the argument for x-match binding. When the X-match parameter is set to any, only one matching header value is sufficient. Alternatively, if x-match is set to all, all values must match.
Welcome Java engineers who have worked for one to five years to join Java architecture development: 855835163 Group provides free Java architecture learning materials (which have high availability, high concurrency, high performance and distributed, Jvm performance tuning, Spring source code, MyBatis, Netty, Redis, Kafka, Mysql, Zookeeper, Tomcat, Docker, Dubbo, multiple knowledge architecture data, such as the Nginx) reasonable use their every minute and second time to learn to improve yourself, don’t use “no time” to hide his ideas on the lazy! While young, hard to fight, to the future of their own account!