AWS SQS and SNS with .NET core - amazon-web-services

I want to implement a publish/subscribe system inside my Micro service application on top of .NET CORE, and since I've everything built on top of AWS, I started to check SQS.
But from what I understood, SQS is only a queue that doesn't offer me that possibility, so yes I can send and read messages to the queue, but I can't have my clients consuming in real time based on topic and sending messages to every client that is subscribing to that topic, right? That's why they have SNS.
From what I understand in order to use SNS, we will always need to have SQS too, but what I'm not finding is how can I integrate SNS on .NET Core? Is there a good tutorial? Because for SQS there's plenty, but for SNS I'm not finding much.

"I'm not finding is how can I integrate SNS on .NET"
There is a brand new AWS tutorial (only a few days old) that shows how to use the AWS.NET API to create an MVC .NET app that uses the .NET SNS API to write a pub/sub app. This example uses .NET async calls as well.
https://github.com/scmacdon/AWSTracker/tree/master/SNSSampleApp

You're right that you should be looking at a combination of SQS and SNS.
SQS lacks pub/sub and SNS lacks competing consumers.
NServiceBus provides all of the middleware needed to work with both of these underlying services correctly and safely, and in .net core. Here's a simple sample: https://docs.particular.net/samples/sqs/simple/
For more information on how it works, check out the docs:
https://docs.particular.net/transports/sqs/

Related

What is the difference between Amazon MQ and SQS?

I am a newbie to AWS. As I understand, both AWS MQ and AWS SQS are Message Queue tools. The only noted difference is that SQS is fully managed.
When should we use SQS or MQ?
SQS is a simple queueing service. It doesn't support many higher level abstractions like message routing, fanouts, distribution lists etc. It is a queue - a message is produced, and a message is delivered. It is useful when you need a Queue with limited backing logic.
AWS MQ is a managed Apache ActiveMQ(or RabbitMQ) broker service.
This provides you a fully managed Apache ActiveMQ system in the cloud, with support for a variety of industry-standard queue and broadcast protocols like AMQP, JMS etc. It is useful when you have complicated delivery rules - or when you're migrating an existing system from outside AWS into AWS, and your systems happen to talk to one another with a standard queueing protocol.
From AWS Documentation, you can search "Q: When should I use Amazon MQ vs. Amazon SQS and SNS?":
Amazon MQ, Amazon SQS, and Amazon SNS are messaging services that are
suitable for anyone from startups to enterprises. If you're using
messaging with existing applications, and want to move your messaging
to the cloud quickly and easily, we recommend you consider Amazon MQ.
It supports industry-standard APIs and protocols so you can switch
from any standards-based message broker to Amazon MQ without rewriting
the messaging code in your applications. If you are building brand new
applications in the cloud, we recommend you consider Amazon SQS and
Amazon SNS. Amazon SQS and SNS are lightweight, fully managed message
queue and topic services that scale almost infinitely and provide
simple, easy-to-use APIs. You can use Amazon SQS and SNS to decouple
and scale microservices, distributed systems, and serverless
applications, and improve reliability.
Also, in this doc, you can check comparisons with other services.

How can i use the Google Cloud IoT data direct in the server based app?

I am new to Google Clout Iot core. I just tried the iot core, registered the device and published some data on a topic.
Now i am wondering is only Google functions are used to get/subscribe data from it? or can i also used the data published from a device directly into my applications e.g. node.js or python? like it is usually subscribed through a normal MQTT topic? I dont need a serverless architecture i want to use the data from google iot into my server and store/use it from there..
thanks a lot!
When a message arrives over MQTT or HTTP from a device over IoT Core, that message is published on a GCP Pub/Sub topic using the GCP Pub/Sub infrastructure. What this means is that you can develop a consuming application however you like as long as that application consumes the message from Pub/Sub.
The diagram shown here from the documentation is a good reference.
GCP exposes the API for Pub/Sub to be a subscriber. There are language bindings for a variety of languages.
Cloud Functions is typically seen as a serverless consumer of Pub/Sub messages as it scales to zero and can scale up if there is bursty load. However, there is nothing to prevent you from writing Compute Engine hosted applications or Container hosted applications which can act as subscribers.
References:
Cloud Pub/Sub documentation
Cloud Pub/Sub Client Libraries
I think your question is more on the architectural side of things. You can use IoT Core with something like Pub/Sub and write the data to Cloud Storage in order to later consume it with an application.
I would recommend you to check some of the diagrams from this page if you are interested in knowing which products you could use to best fit your needs.
I hope you find this useful!

How is Amazon Appsync's subscription different from Amazon SNS? Which one is the right tool for a chat application?

AFAIK, one key difference between the two is that Appsync is implemented using MQTT and has an emphasis on real-time notification, while SNS is more like a general pub/sub service.
The real-time notification part of Appsync seems to be the right tool for a chat application. However with Appsync, I will not be able to push the notification to users if a connection is not established(?)
I would like to have real-time notification for users regardless the application is opened or not. What is the right tool for this purpose?
Generally, you'll probably have a more "ready-to-use" solution for chat using AppSync, e.g. https://aws.amazon.com/blogs/mobile/building-a-serverless-real-time-chat-application-with-aws-appsync/
Using SNS will probably provide more flexibility at the cost of more of your time wiring up custom code.
You are correct that AppSync doesn't natively support push notifications for background applications; for that, you'd need to wire in something like SNS. You could probably couple AppSync with SNS using an AppSync Lambda resolver.
Depending on your requirements, i.e. if it's not essential that a system notification appears for new messages, you can also query AppSync at app startup time for chat messages that were received while the client was disconnected.

Replicate SNS Topic subscription from one device end point to another

I have an android device that is registered to an SNS Platform Application. So it is a platform endpoint (in terms of aws sns). It has subscribed a total of 20 Sns Topics.
If I have another device (Android or Iphone), which is also an SNS platform endpoint, I would like it to be subscribed to same SNS topics.
Basically, I want to subscribe sns topics from one device. And if I install this application to another device, I want all of my subscription to be replicated on that other device as well. I hope I made my self clear.
I am using AWS SDK for Asp.net core.
Thanks for helping out.
Essentially for GCM another device would require another subscription.
The logic below will not work automatically unless you program it in your application.
Basically, I want to subscribe sns topics from one device. And if I install this application to another device, I want all of my subscription to be replicated on that other device as well. I hope I made my self clear.
Please check this example in mobile-platform-endpoint documentation, it is not the same scenario but can be used as reference.

How does AWS SNS send Application notifications?

I have a React Native application that works on iOS and Android and I am looking to integrate AWS SNS. I have some questions that I hope people with SNS experience could answer.
From my understanding, AWS SNS is merely a gateway for using GCM (Android) and APNS (iOS)
Is this correct?
If the above is correct, imagine that I have an Android-only app, what's the point of using AWS SNS when I could directly use GCM/Firebase? I can even use Firebase with iOS.
My app needs to allow a single User to send a notification to one or more Users.
Is there an RESTful API I can consume to achieve this?
Or would I need to set up API Gateway and use Lambda functions?
How do I automatically store tokens on SNS?
I read that I have to integrate AWS Cognito for this, or use a Proxy Server.
Edit:
I've managed to write a Node.js server that uses the aws-sdk to communicate with SNS.
Questions corresponding to their above question numbers
Still looking for answers
Still looking for answers
I've written a Node server, I suppose I could embed the aws-sdk code into my React Native app as it can use Node APIs
For question #4 - I used createPlatformEndpoint
I am no specialist but given you have not received an answer yet, I thought I would try to help
you can use AWS SNS to send messages via GCM, but it can do much more, since it's a pub-sub service: for example, if can be configured to receive email complaints from mails sent by AWS SES, and then you get either either a lambda function or a queue (SQS) to receive those actions emitted by SNS, allowing you to act on them
for an Android-app only I don't see a good reason to bother, and even if it was also on iOS, you could configure yourself the sending of push notifications with an if/else in your code. I could argue it's a matter of personal taste, whether you want more configuration in your code vs in the infra-structure (I know the limit can get blurry), but it seems so much easier to keep it in the code that I wouldn't believe a word I said
My app needs to allow a single User to send a notification to one or
more Users.
If it's a user writing to 1 to a few users, like in a messaging app, I would say it's easier to define (and maintain) the logic within your app and iterate over the group of recipients to send the push notifications.
If you're going to have a few people who are going to be followed by thousands of people and needs to write to them, you might have a case for using SNS Topics (each "popular user" can write - maybe via your own api - to an SNS topic to which the "followers" subscribed; keep in mind the max number of topics you can create), as SNS will take care of any scaling issue (it can take time and resources to send a push notification to your 1 million followers)
What you said if you're going to user SNS, otherwise sending a push notification via GCM/FCM is as simple as a POST request.