Posts

Showing posts from June, 2020

Alternate exchange là gì và khi nào dùng

https://www.rabbitmq.com/ae.html Alternate exchange là 1 exchange thay thế. Được chỉ định khi bạn khởi tạo 1 cái exchange.  Vấn đề là khi bạn đẩy 1 msg với 1 routing-key vào 1 exchange. Nhưng nếu exchange này chưa binding đến bất kì queue nào hoặc là không có routing-key nào macthed với routing-key của msg thì lúc này msg sẽ đc đẩy vào alternate exchange.

Tiếp theo là độ dài của queue

https://www.rabbitmq.com/maxlength.html Theo bạn thì độ dài của queue là xác định thế nào? Trong rabbitMQ thì độ dài của queue có thể đc setup theo policy theo 2 khía cạnh 1. là queue có thể chứa bao nhiêu phần tử 2. là độ dài bytes của tổng số các phần tử trong queue, ví dụ khai báo là tổng số phần tử trong queue là 2MB=> nếu 1 phần tử mới vào làm cho khối lượng tăng lên hơn 2MB thì phần tử sẽ drop hoặc forward tiếp Ví dụ sét số phần tử max-length của 1 queue  Map<String, Object> args = new HashMap<String, Object>(); args.put("x-max-length", 10); channel.queueDeclare("myqueue", false, false, false, args); Define Max Queue Length Using x-arguments During Declaration Maximum number of messages can be set by supplying the x-max-length queue declaration argument with a non-negative integer value. Maximum length in bytes can be set by supplying the x-max-length-bytes queue declaration argument with a non-negative integer value. If both arguments are set...

Dead Letter Exchanges

https://www.rabbitmq.com/dlx.html Tại sao lại cần thuộc tính này.  Tôi sẽ lấy ví dụ: về overflow, hoặc message Time to live, hoặc consumer reject hoặc nack Ví dụ bạn có 1 cái queue mà maximum length của queue là 10 phần tử, hiểu theo cách khác là độ dài của queue là 10 Khi đó nếu phần tử thứ 11 được đẩy vào thì làm sao--> sẽ có 1 phần tử bị drop,-> phần tử đầu queue hay cuối queue sẽ bị drop ==> tùy thuộc vào cách bạn setup policcy cho Queue Overflow behavior can be set by supplying the x-overflow queue declaration argument with a string value. Possible values are drop-head (default) or reject-publish ==> Để tránh miss messages khi bị tràn queue => cần phải chỉ rõ thuộc tính này khi khởi tạo queue Map<String, Object> args = new HashMap<String, Object>(); args.put("x-dead-letter-exchange", "some.exchange.name"); channel.queueDeclare("myqueue", false, false, false, args); Tiếp theo là sau khi message được đẩy vào exchange mới rồ...

Cách tạo delay queue

https://ivanyu.me/blog/2015/02/16/delayed-message-delivery-in-rabbitmq/ We will need several queue arguments, which will be set on its declaration: x-message-ttl  – the number of milliseconds for a message to stay consumed in a queue. x-dead-letter-exchange  and  x-dead-letter-routing-key  – an exchange and routing key where message will be send after the expiration. x-expires  – the number of milliseconds for a queue to be unused before it will be deleted.

Cách tạo delay exchange

https://www.rabbitmq.com/blog/2015/04/16/scheduling-messages-with-rabbitmq Step 1:  Installing the Plugin To install the plugin go to our  Community Plugins page  and download the corresponding .ez files for your RabbitMQ installation. Copy the plugin into RabbitMQ's plugin folder and then enable it by running the following command: rabbitmq-plugins enable rabbitmq_delayed_message_exchange Step 2: Tạo exchange Type : x-delayed-message args: ("x-delayed-type", "direct"); Step 3: Send Message headers.put(" x-delay", 5000); <=> 5000 ms or 5 seconds

Các thuộc tính khi tạo mới một queue

Durable (the queue will survive a broker restart) Exclusive (used by only one connection and the queue will be deleted when that connection closes) Auto-delete (queue that has had at least one consumer is deleted when last consumer unsubscribes) Arguments (optional; used by plugins and broker-specific features such as message TTL, queue length limit, etc)

Phân biệt các loại exchange trong rabbitMQ

direct: Là loại exchange mà khi bạn đẩy 1 event kèm 1 routing-key thì event này sẽ được khớp chính xác với routing-key tương ứng queue fanout: Là loại exchange mà nó sẽ đẩy event vào bất kì cái queue nào đang nhận routing từ exchange đó topic: Là loại exchange mà nó sẽ đẩy event vào bất kì cái queue nào mà có routing key matched theo các quy ước ký tự (*, #)  header:  exchanges are similar to Topic exchanges, except instead of pattern matching on the routing key, they use the message header attributes for matching https://www.rabbitmq.com/tutorials/tutorial-five-python.html https://www.compose.com/articles/configuring-rabbitmq-exchanges-queues-and-bindings-part-1/ https://www.compose.com/articles/configuring-rabbitmq-exchanges-queues-and-bindings-part-2/

git config

You can use the --unset flag of git config to do this like so: git config --global --unset user.name git config --global --unset user.email If you have more variables for one config you can use: git config --global --unset-all user.name

Careful when comparing value with nil in Golang

func main () { err := Foo () fmt . Println ( err == nil ) } func Foo () error { var err * os . PathError = nil return err } /tmp/___go_build_main_go #gosetup false Process finished with exit code 0 Best practice func main () { err := Foo () fmt . Println ( err == nil ) } func Foo () error { var err * os . PathError = nil if err != nil { return errors . New ( "Not nil" ) } return nil } /tmp/___go_build_main_go #gosetup true Process finished with exit code 0