SP API NOTIFICATION SQS TO SNS

0

I'm using SP-API to create notification messages whenever a product's offer changes (notification type: ANY_OFFER_CHANGED).

It is working because I can see messages when I go to Amazon SQS --> Queues and I can see a bunch of messages available.

My question: What function in the API do we call in our application in order to actually get and enumerate through the messages?

Calling getDestination() or getSubscription() only seem to return ID's in the payload, but I don't know what function to call in order to enumerate through all these messages sitting in the Queue.

Our goal is to call our application every few minutes to process messages and update the prices of our products based on these notification messages in the queue. I just need someone to point me on what API function is used to retrieve these messages.

jam
asked 22 days ago56 views
1 Answer
0

Hello.

Please use "receive_message()" to retrieve messages from the SQS queue.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sqs/client/receive_message.html#

Also, even if you display the message with "receive_message()", it will remain in the SQS queue, so if you successfully retrieve the message, please delete it with "delete_message()".
If you don't delete the message, the same message will be processed over and over again.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sqs/client/delete_message.html

The code below is a sample that retrieves messages from an SQS queue called test in the Tokyo region.

import boto3
import json
import time

sqs = boto3.client('sqs', region_name='ap-northeast-1')

queue_url = 'https://sqs.ap-northeast-1.amazonaws.com/1111111111/test'
while True:
    response = sqs.receive_message(
        QueueUrl=queue_url,
        AttributeNames=[
            'All'
        ],
    )

    if 'Messages' in response:
        sqs_message = json.loads(response['Messages'][0]['Body'])
        print(sqs_message)

        message_del = sqs.delete_message(
            QueueUrl=queue_url,
            ReceiptHandle=response['Messages'][0]['ReceiptHandle']
        )
        time.sleep(60)
    else:
        print ('No Messages')
        break
profile picture
EXPERT
answered 22 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions