Skip to content

Commit

Permalink
Add delete notification optional
Browse files Browse the repository at this point in the history
  • Loading branch information
abuzuhri committed Mar 3, 2024
1 parent ed91821 commit 288086f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
17 changes: 14 additions & 3 deletions Source/FikaAmazonAPI.SampleCode/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,29 @@ static async Task Main(string[] args)
IsDebugMode = true
});

//var feedTypes = new ParameterGetFeed { feedTypes = { FeedType.POST_PRODUCT_PRICING_DATA }, processingStatuses = ProcessingStatuses.IN_PROGRESS };

FeedsSample feedsSample = new FeedsSample(amazonConnection);
feedsSample.SubmitFeedPRICING(69.3F, "8809606851663");
//var feeds = amazonConnection.Feed.GetFeeds(feedTypes);


//FeedsSample feedsSample = new FeedsSample(amazonConnection);
//feedsSample.SubmitFeedPRICING(69.3F, "8809606851663");

var feeds = amazonConnection.Feed.GetFeeds(new Parameter.Feed.ParameterGetFeed()
{
processingStatuses = ProcessingStatuses.IN_QUEUE,
processingStatuses = ProcessingStatuses.IN_PROGRESS,//ProcessingStatuses.IN_QUEUE,
pageSize = 100,
feedTypes = new List<FeedType> { FeedType.POST_PRODUCT_PRICING_DATA },
marketplaceIds = new List<string> { MarketPlace.UnitedArabEmirates.ID }
});

var feeds2 = amazonConnection.Feed.GetFeeds(new Parameter.Feed.ParameterGetFeed()
{
processingStatuses = ProcessingStatuses.IN_PROGRESS,//ProcessingStatuses.IN_PROGRESS,
pageSize = 100,
feedTypes = new List<FeedType> { FeedType.POST_INVENTORY_AVAILABILITY_DATA },
marketplaceIds = new List<string> { MarketPlace.UnitedArabEmirates.ID }
});
foreach (var feed in feeds)
{
Console.WriteLine("FeedId " + feed.FeedId);
Expand Down
18 changes: 11 additions & 7 deletions Source/FikaAmazonAPI/Services/NotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ public async Task<bool> DeleteSubscriptionByIdAsync(NotificationType notificatio
return true;
}

public void StartReceivingNotificationMessages(ParameterMessageReceiver param, IMessageReceiver messageReceiver) =>
Task.Run(() => StartReceivingNotificationMessagesAsync(param, messageReceiver)).ConfigureAwait(false).GetAwaiter().GetResult();
public void StartReceivingNotificationMessages(ParameterMessageReceiver param, IMessageReceiver messageReceiver, bool isDeleteNotificationAfterRead = true) =>
Task.Run(() => StartReceivingNotificationMessagesAsync(param, messageReceiver, isDeleteNotificationAfterRead)).ConfigureAwait(false).GetAwaiter().GetResult();

public async Task StartReceivingNotificationMessagesAsync(ParameterMessageReceiver param, IMessageReceiver messageReceiver, CancellationToken cancellationToken = default)
public async Task StartReceivingNotificationMessagesAsync(ParameterMessageReceiver param, IMessageReceiver messageReceiver, bool isDeleteNotificationAfterRead = true, CancellationToken cancellationToken = default)
{
var awsAccessKeyId = param.awsAccessKeyId;
var awsSecretAccessKey = param.awsSecretAccessKey;
Expand All @@ -140,7 +140,7 @@ public async Task StartReceivingNotificationMessagesAsync(ParameterMessageReceiv
{
foreach (var msg in Messages)
{
ProcessAnyOfferChangedMessage(msg, messageReceiver, amazonSQSClient, SQS_URL, cancellationToken).ConfigureAwait(false);
ProcessAnyOfferChangedMessage(msg, messageReceiver, amazonSQSClient, SQS_URL, isDeleteNotificationAfterRead, cancellationToken).ConfigureAwait(false);

}

Expand All @@ -156,19 +156,23 @@ public async Task StartReceivingNotificationMessagesAsync(ParameterMessageReceiv
}
}

private async Task ProcessAnyOfferChangedMessage(Message msg, IMessageReceiver messageReceiver, AmazonSQSClient amazonSQSClient, string SQS_URL, CancellationToken cancellationToken = default)
private async Task ProcessAnyOfferChangedMessage(Message msg, IMessageReceiver messageReceiver, AmazonSQSClient amazonSQSClient, string SQS_URL, bool isDeleteNotificationAfterRead = true, CancellationToken cancellationToken = default)
{
try
{
var data = DeserializeNotification(msg);

messageReceiver.NewMessageRevicedTriger(data);
await DeleteMessageFromQueueAsync(amazonSQSClient, SQS_URL, msg.ReceiptHandle, cancellationToken);

if (isDeleteNotificationAfterRead)
await DeleteMessageFromQueueAsync(amazonSQSClient, SQS_URL, msg.ReceiptHandle, cancellationToken);
}
catch (Exception ex)
{
messageReceiver.ErrorCatch(ex);
await DeleteMessageFromQueueAsync(amazonSQSClient, SQS_URL, msg.ReceiptHandle, cancellationToken);

if (isDeleteNotificationAfterRead)
await DeleteMessageFromQueueAsync(amazonSQSClient, SQS_URL, msg.ReceiptHandle, cancellationToken);
}
}
private async Task DeleteMessageFromQueueAsync(AmazonSQSClient sqsClient, string QueueUrl, string ReceiptHandle, CancellationToken cancellationToken = default)
Expand Down

0 comments on commit 288086f

Please sign in to comment.