Home > Software design >  How to subscribe/receive AWS SNS messages in C#?
How to subscribe/receive AWS SNS messages in C#?

Time:02-22

I am developing C# applications, and I'd like to implement using of AWS SNS. I understand how to publish SNS from my C# app, but how can I subscribe/receive SNS in C#? Is it possible at all?

CodePudding user response:

It would appear that you want to do message-passing between applications.

For this use-case, I would recommend using Amazon Simple Queue Service (Amazon SQS) rather than using Amazon Simple Notification Service (Amazon SNS).

Basically:

  • App1 sends a message to an Amazon SQS queue
  • App2 regularly polls (looks in) the queue to see if there is a message for it to process. If so, it grabs the message
  • Amazon SQS makes the message 'invisible' so no other worker will see it
  • When App2 has finished processing the message, it deletes the message from the queue
  • If App2 does not delete the message within a defined 'invisibility period', then the message will automatically 'reappear' on the queue so that it can be re-processed

This is a more-rigorous method of message-passing since it can handle situations where errors occur or where the target app is not currently running.

Amazon SNS, in contrast, simple sends the message to the desired destination (such as an HTTP endpoint), which will fail if the target app is not running.

  • Related