21 Ocak 2021 Perşembe

AMQP Frame Tipleri

Giriş
Frame yapısı şöyledir


1. Frame Header
Her frame'in başında bir header var

1. 1. Type Alanı
Açıklaması şöyle
The first byte stores the type of the frame and can assume the value HEADER, METHOD, BODY or HEARTBEAT. 
5 çeşit Frame Type var. Bunlar şöyle

1.1.1 Protocol header
Açıklaması şöyle. Sadece bağlantı kurulurken kullanılır
This is the frame sent to establish a new connection between the broker (RabbitMQ) and a client. It will not be used anymore after the connection.
1.1.2 Method frame
Açıklaması şöyle.  Basic.Publish, Basic.Deliver gibi işler içindir
Carries a RPC request or response. AMQP uses a remote procedure call (RPC) pattern for nearly all kind of communication between the broker and the client. For example, when we are publishing a message, our application calls Basic.Publish, and this message is carried in a method frame, that will tell RabbitMQ that a client is going to publish a message.
1.1.3 Content header
Açıklaması şöyle.  Belli Method frame tiplerinden sonra gönderilir. Header frame içindeki bir çok alana bu yazıda aşağıda açıklanıyor.
Certain specific methods carry a content (like Basic.Publish, for instance, that carries a message to be published), and the content header frame is used to send the properties of this content. For example, this frame may have the content-type of a message that is going to be published and a timestamp.
1.1.4 Body
Açıklaması şöyle
This is the frame with the actual content of your message, and can be split into multiple different frames if the message is too big (131KB is the default frame size limit).
1.1.5 Heartbeat
Açıklaması şöyle
Used to confirm that a given client is still alive. If RabbitMQ sends a heartbeat to a client and it does not respond in timely fashion, the client will be disconnected, as it’s considered dead.
1.2 Channel Alanı
 Açıklaması şöyle. Frame Header içindeki ikinci alandır
The next byte stores the channel which identifies an independent thread of messages. Although the client establishes only a single TCP connection with the Message Broker, the connection is multiplexed — contrary to HTTP/1.1. This means that the client and the message-broker can utilise the same TCP connection to transmit multiple independent threads of messages. 
1.3. Size Alanı
Açıklaması şöyle.  Frame Header içindeki üçüncü alandır. Geriye kaç byte kaldığını belirtir.
The next byte indicates the size of the Payload.  
Frame Sonu
Her Frame'in sonunda da End Byte Marker diye bir şey daha var sanırım

Publish İşlemi
Toplam 3 frame kullanılır. Sırası şöyle
1. Method Frame'lerden birisi olan Basic.Publish Frame
2. Content Header Frame 
3. N tane Body Frame


Deliver İşlemi
Toplam 3 frame kullanılır. Sırası şöyle
1. Method Frame'lerden birisi olan Basic.Deliver Frame
2. Content Header Frame 
3. N tane Body Frame


Basic.Publish Frame İşlemi İçin Header Frame
Mesaj publish etmek için kullanılır



1. expiration
Mesajlar için expiration değeri tanımlanabilir. Mesajın header alanına "expiration" ve milisaniye cinsinden string değeri atanıyor. Eğer expire eden mesajlar için "Dead Letter Exchange" tanımlı değilse, mesaj silinir. 

2. priority
Açıklaması şöyle
RabbitMQ supports something called priority queues, meaning that a queue can be set to have a range of priorities. The priority of each message can be set when it is published. Depending on the priority of the message it is placed in the appropriate priority queue. 
Açıklaması şöyle
As of RabbitMQ 3.5.0, the priority field has been implemented as per the AMQP specification. It’s defined as an integer with possible values of 0 through 9 to be used for message prioritization in queues. As specified, if a message with a priority of 9 is published, and subsequently a message with a priority of 0 is published, a newly connected consumer would receive the message with the priority of 0 before the message with a priority of 9. Interestingly, RabbitMQ implements the priority field as an unsigned byte, so priorities could be anywhere from 0 to 255, but the priority should be limited to 0 through 9 to maintain interoperability with the specification. 
3. delivery-mode 
İki tane değere sahiptir. Açıklaması şöyle
The delivery-mode property has two possible values: 1 for a non-persisted message and 2 for a persisted message.
non-persisted mesajları broker saklamaz. Yanı broker yeniden başlatılırsa mesajlar kaybolur. Eğer saklanması isteniyorsa persistent modda kullanmak gerekir. Bir başka açıklama şöyle
RabbitMQ is often used with Apache Cassandra when application needs access to stream history, or with the LevelDB plugin for applications that need an “infinite” queue, but neither feature ships with RabbitMQ itself.
4. timestamp
 Açıklaması şöyle
Like message-id and correlation-id, timestamp is specified as “for application use.” Even if your message doesn’t use it, the timestamp property is very helpful when you’re trying to diagnose any type of unexpected behavior in the flow of messages through RabbitMQ. By using the timestamp property to indicate when a message was created, consumers can gauge performance in message delivery.
5. appid
Açıklaması şöyle. Mesajı üreten uygulamanın ismidir
The app-id property is defined in the AMQP specification as a “short-string,” allowing for up to 255 UTF-8 characters. If your application has an API-centric design with versioning, you could use the app-id to convey the specific API and version that were used to generate the message. As a method of enforcing a contract between publisher and consumer, examining the app-id prior to processing allows the application to discard the message if it’s from an unknown or unsupported source.
6.  user-id
Açıklaması şöyle. Mesajı üreten uygulamanın ismidir
In the use case of user authentication, it may seem obvious to use the user-id property to identify the user who has logged in, but in most cases this isn’t advisable. RabbitMQ checks every message published with a value in the user-id property against the RabbitMQ user publishing the message, and if the two values don’t match, the message is rejected. For example, if your application is authenticating with RabbitMQ as the user “www”, and the user-id property is set to “linus”, the message will be rejected.

Hiç yorum yok:

Yorum Gönder