Search code examples
pythonazurequeueazure-queues

How can I get the insertion_time value of an object in an Azure queue


I need to get the insertion time of an object in the queue. I can get the message but that's not the goal, I just want to know how long the message has been in the queue

When I try message.insertion_time I receive this error "AttributeError: 'QueueMessage' object has no attribute 'insertion_time'"

my code in Python

queue_service = QueueServiceClient(storage_url,credential)
queue_cliente = queue_service.get_queue_cliente(queue_name)
messages = queue_client.peek_messages()

if messages:
  for message in messages:
     print(message.insertion_time)
else:
print("Empty list")

Solution

  • Based on the documentation here, the correct name of the property is inserted_on and not insertion_time. Please try by using that.

    queue_service = QueueServiceClient(storage_url,credential)
    queue_cliente = queue_service.get_queue_cliente(queue_name)
    messages = queue_client.peek_messages()
    
    if messages:
      for message in messages:
         print(message. inserted_on)
    else:
    print("Empty list")