Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to peek at messages in the queue

I don't want the message to count as "read" but I'd like to know what's in the queue. The documentation:

http://boto.s3.amazonaws.com/ref/sqs.html#module-boto.sqs

Isn't very straight forward about what absorbs a message and what doesn't. The dump message seems close, but I'd rather do this in memory rather than to a file.

The faq:

http://aws.amazon.com/articles/1343#12

Has some sketchy solution:

How do I peek at a message?

With version 2008-01-01, the PeekMessage action has been removed from Amazon SQS. This functionality was used mainly to debug small systems — specifically to confirm a message was successfully sent to the queue or deleted from the queue. To do this with version 2008-01-01, you can log the message ID and the receipt handle for your messages and correlate them to confirm when a message has been received and deleted.

Has anyone had any luck with this? It seems like very basic queue functionality and I'd be shocked if there wasn't a clean way to do this.

like image 848
Ralphleon Avatar asked Apr 11 '12 05:04

Ralphleon


People also ask

What is Peek in message queue?

The Peek() method is synchronous, so it blocks the current thread until a message becomes available or the specified time-out occurs. Peek(TimeSpan, Cursor, PeekAction) Returns without removing (peeks) the current or next message in the queue, using the specified cursor.

What are the tasks of a message queue?

A message queue provides a lightweight buffer which temporarily stores messages, and endpoints that allow software components to connect to the queue in order to send and receive messages. The messages are usually small, and can be things like requests, replies, error messages, or just plain information.


2 Answers

Right click no longer works in the new SQS console.

To view queue messages in the SQS console you now need to click into a queue > Send and receive messages > Poll for messages

like image 192
marmor Avatar answered Oct 05 '22 11:10

marmor


There is no longer a true peek function available in SQS but you can probably accomplish what you want by simply using get_messages and setting the visibility_timeout quite low. As long as you don't delete the messages you have read, they will reappear on the queue after the visibility_timeout has expired and will be available for reading. The only tricky part is trying to figure out how long the timeout should be. If you have lots and lots of messages in the queue, you will have to make multiple calls to get_messages to retrieve them all and you probably don't want previously read messages reappearing while you are still peeking at the messages.

like image 45
garnaat Avatar answered Oct 05 '22 10:10

garnaat