What API function to call to get subscription notification messages?


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.

asked a year ago392 views
2 Answers

To receive subscription notification messages in Amazon Simple Queue Service (SQS), you need to create an SQS queue and then subscribe it to the SNS topic. Once you have done that, you can use the ReceiveMessage API function to retrieve the subscription notification messages from the SQS queue. For enumerate through the message in an SQS queue then you use a loop to repeately call the 'ReceiveMessage' API function until there are no more messages in the queue.

Here's an example of how to use the ReceiveMessage function in the AWS SDK for Python (Boto3):

import boto3
# Create an SQS client
sqs = boto3.client('sqs')
# Specify the URL of the SQS queue
queue_url = 'https://sqs.region.amazonaws.com/account-id/queue-name'
# Receive messages from the SQS queue in a loop
while True:
    response = sqs.receive_message(
    # Process the messages
    if 'Messages' in response:
        for message in response['Messages']:
        print('No more messages in the queue')

The messages from the queue in the same format in which we are sending them to the queue. If we are sending encrypted messages then we would receive encrypted messages only. if the messages are base64 encoded then you can write a code at your end to receive the messages using the ReceiveMessage API call[1]. Once you have the messages, you can then decode the received message using base64 library in your code. You can refer the links[2][3] for Encoding and Decoding Base64 Strings.

[1]. https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_ReceiveMessage.html [2]. https://www.geeksforgeeks.org/encoding-and-decoding-base64-strings-in-python/ [3]. https://stackoverflow.com/questions/3470546/python-base64-data-decode

answered a year ago

I am also struggling on this point, unable to send notifications from SQS to SNS and then SNS to any subscriber

answered 2 months 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