1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| ## 透過rabbitctl rabbitmqctl set_policy TTL ".*" '{"message-ttl":60000}' --apply-to queues
## 透過http curl -i -u guest:guest -H "content-type:application/json" -XPUT -d'{"auto_delete":false,"durable":true,"arguments":{"x-message-ttl": 60000}}' http://localhost:15672/api/queues/{vhost}/{queuename}
## Per-Message TTL (發布事件時對訊息加入TTL) var body = Encoding.UTF8.GetBytes($"{message}"); var prop = channel.CreateBasicProperties(); prop.Expiration = $"{ttl}"; // Expiration是字串格式單位為秒正整數
channel.BasicPublish( $"{exchange}", $"{routingKey}", prop, body);
## Queue TTL (對Queue設定TTL) //// generate queue var args = new Dictionary<string, object>(); args.put("x-expires", $"{ttl}"); // Expiration是字串格式單位為秒正整數 channel.QueueDeclare($"{queue}", false, false, false, args);
|