Currently I'm trying to send data to a azure queue in storage. I am able to send data but I am unable to custom the expiration time like to 10 seconds 1 day like that. But in azure portal able to do it.
below image azure portal
below is the code
from azure.storage.queue import QueueClient, QueueMessage
from datetime import datetime, timedelta
import time
# Replace with your actual Azure Storage account details
account_name = 'you_account_name'
account_key = 'your_account_key'
connection_string = f"DefaultEndpointsProtocol=https;AccountName={account_name};AccountKey={account_key};EndpointSuffix=core.windows.net"
def send_message_to_queue(queue_name, message, ttl_seconds):
# Instantiate a QueueClient
queue_client = QueueClient.from_connection_string(connection_string, queue_name)
# Send message to queue auto expirey in 5 secs
queue_client.send_message(queue_message, time_to_live = ttl_seconds)
print(f"Message '{message}' sent to queue '{queue_name}' with expiration in {ttl_seconds} seconds.")
if __name__ == "__main__":
queue_name = 'your_queue_name'
message = "hello"
ttl_seconds = 5 # TTL of 5 seconds
for coordinate in coordinates:
send_message_to_queue(queue_name, message, ttl_seconds)
time.sleep(5)
when I run this program the expiration is still 7 days as per in the image