Producer, Queue ile direkt konuşmaz. Arada Exchange yapısı vardır. Eğer tek bir queue varsa Exchange yapısı biraz mantıksız görünebilir. Exchange ile kuyruğun birbirine bağlanmasına binding denilir.
Producer routing key değeri ile mesaj gönderir. Exchange ise binding key ile karşılaştırarak eşleşen kuyruğa yönlendirir. Şeklen şöyle
Producer routing key değeri ile mesaj gönderir. Exchange ise binding key ile karşılaştırarak eşleşen kuyruğa yönlendirir. Şeklen şöyle
Exchange çeşitleri şöyle
1. Direct Exchange
Direct Exchange yazısına taşıdım
2. Topic Exchange
Routing key ve Binding key kısmen eşleşirse mesajı kuyruğa yönlendirir. Yani bu exchange'a bağlı bir sürü kuyruk varsa tüm uyan kuyruklara gönderir. Açıklaması şöyle
Topic exchange is similar to direct exchange, but the routing is done according to the routing pattern. Instead of using fixed routing key, it uses wildcards. Messages are routed to one or many queues based on a matching between a message routing key and pattern. The routing key must consist of list of words delimited by a period “.”.For example, let’s suppose we have following routing patterns.- order.logs.customer- order.logs.international- order.logs.personnel- order.logs.customer.electronics- order.logs.personnel.electronics- order.logs.international.electronicsThe routing patterns may also contain an asterisk (“*”) to match a word in a specific position of the routing key. For example, a routing pattern of “order.*.*.electronics” only match routing keys where the first word is “order” and the fourth word is “electronics”.The routing pattern may also contain a pound symbol (“#”) which means a match of zero or more words. For example, a routing pattern of “order.logs.customer.#” matches any routing keys beginning with “order.logs.customer “.
4. Header Exchange
Routing key yerine message header kullanılır. Açıklaması şöyle
A headers exchange routes messages based on arguments containing headers and optional values. It uses the message header attributes for routing.A special argument named “x-match”, added in the binding between exchange and queue, specifies if all headers must match or just one. The “x-match” property can have two different values: “any” or “all”,where “all” is the default value. A value of “all” means all header pairs (key, value) must match, while value of “any” means at least one of the header pairs must match.
5. Default (nameless) Exchange
Eğer queue için Exchange tanımlanmazsa exchange otomatik yaratılır. Routing key = queue name ise mesaj kuyruğa yönlendirilir. Açıklaması şöyle
The default exchange is a pre-declared direct exchange that has no name. It is usually referred by an empty string. If you use default exchange your message is delivered to the queue with a name equal to the routing key of the message. Every queue is automatically bound to the default exchange with a routing key which is the same as the queue name.
6. Dead Letter Exchange
Açıklaması şöyle
If there is no matching queue for the message, the message is dropped. RabbitMQ provides an AMQP extension known as the “Dead Letter Exchange”. This exchange which provides the functionality to capture messages that are not deliverable.
Genel kullanım DLX için 3 tane sebep var. Açıklaması şöyle
In fact, in RabbitMQ, there are three forms of "death" in three messages:- The message was rejected. By calling basic.reject or basic.nack and setting the requeue parameter to false.- The message expired because the TTL was set.- The message enters a queue that has reached its maximum length.
Hiç yorum yok:
Yorum Gönder