What API function to call to get subscription notification messages?

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.

Jeff
質問済み 1年前431ビュー
2回答
0

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(
        QueueUrl=queue_url,
        MaxNumberOfMessages=10,
        VisibilityTimeout=0,
        WaitTimeSeconds=0
    )
    # Process the messages
    if 'Messages' in response:
        for message in response['Messages']:
            print(message['Body'])
            sqs.delete_message(
                QueueUrl=queue_url,
                ReceiptHandle=message['ReceiptHandle']
            )
    else:
        print('No more messages in the queue')
        break

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

AWS
回答済み 1年前
0

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

jam
回答済み 4ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ