Dead Letter Exchanges
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ồi thì nó sẽ tiếp tục đi vào đâu, dựa trên routing-key nào
Bạn cần tiếp tục chỉ rõ tham số
args.put("x-dead-letter-routing-key", "some-routing-key");
Nếu bạn không chỉ rõ tham số này thì Message sẽ được forward đi với chính cái routing-key mà trước đó đã đẩy message
Routing Dead-Lettered Messages
Dead-lettered messages are routed to their dead letter exchange either:
with the routing key specified for the queue they were on; or, if this was not set,
with the same routing keys they were originally published with
For example, if you publish a message to an exchange with routing key foo, and that message is dead-lettered, it will be published to its dead letter exchange with routing key foo. If the queue the message originally landed on had been declared with x-dead-letter-routing-key set to bar, then the message will be published to its dead letter exchange with routing key bar.
Comments
Post a Comment