rabbitmqctl - How to read RabbitMQ unacknowledged messages / RabbitMQ cycle -
i want read payload, or messageid of unacknowledged messages in rabbitmq queue. possible?
the reason want trying use rabbitmq dead letter feature build cycle auto-generating message periodically. briefly, create 2 queues - work queue , delay queue.
- set ttl of message in delay queue time frequency of need periodically. can have different messages different ttl different job purpose;
- put message delay queue. when message expires, gets republished work queue. message can sit in work queue long needed until consumer consume it.
- one consumer picks message, , process it. if processing succeeds, consumer needs acknowledge work queue, , write message delay queue; if processing fails (e.g., thread crashes), no acknowledgement. message re-appear in worker queue automatically. consumer can take job. when message sent delay queue gets expired again, gets republished, re-consumed consumer ...... cycle constructed, workload distributed.
i want make sure there no missing or duplicate messages in cycle since not want missing job or double doing job @ same time. however, there tiny tiny chance duplicate messages can happen. below show consumer first write message delay queue, , acknowledge work queue. if thread crashes right between below 2 lines, message in delay queue, , rabbit republish message again work queue. end duplicate messages in cycle.
channel.basicpublish(delay_exchange, "", null, message.getbytes()); channel.basicack(delivery.getenvelope().getdeliverytag(), false);
to prevent above, want add dog watch logic after above 2 line:
check total number of messages in cycle (total messages in both queues) see whether equal expected number (i expected number less 10);
if number not matches, want figure out 1 missing or 1 duplicate, deal it. not care sequence of messages, or frequency has been disturbed since really edge case consider. can retrieve messages ready , requeue them. problem how deal unacknowledged messages?
thank in advance!
roy
it's not possible read unacknowledged messages other context original messages consumed , held un-aked.
Comments
Post a Comment