samedi 30 mai 2015

How to send server side notifications using rails & aws to phonegap device

I'm searching for a solution for sending server side notifications from rails to a cordova app for a certain set of devices at a particular point in time.

Let's say users place bids for an item. Each time a bid is placed on that item, every user who posted a bid needs to be notified. The notification needs to take the form of a JS callback.

Now I'm digging through examples of AWS SNS but I fear it doesn't fit my purpose. The flow on AWS SNS is roughly this one

Platform_applicaton --> Platform_endpoint --> subscription for a topic



require 'rubygems'
require 'aws-sdk'


sns = Aws::SNS::Client.new(
  access_key_id: 'X',
  secret_access_key: 'X',
  region: 'X',
  ssl_ca_bundle: 'c:\tmp\ca-bundle.crt'
)

# create platform application
platform_app = sns.create_platform_application(
  # required
  name: "parking-space-web",
  # required
  platform: "GCM",
  # required
  attributes:
    { :PlatformCredential => "google_api_key" ,
      :PlatformPrincipal => "" }
)

puts platform_app['platform_application_arn']

#create endpoint
endpoint = sns.create_platform_endpoint(
  # required
  platform_application_arn: platform_app['platform_application_arn'],
  # required
  token: "app1"
)

# subscribe to topic
subscription = sns.subscribe(
  # required
  topic_arn: "arn:aws:topic:arn",
  # required
  #I can choose whatever protocol I want but the physical notification will    just be a call made via that specific protocol ( http/email ).
  protocol: "application", 
  endpoint: endpoint['endpoint_arn'],
)

How is that useful to me? I'm publishing a message via http/email which is plainly sent to multiple http/email subscribers. If I needed that I would simply make the http/email requests myself. What's the advantage of SNS?

I figure that the real deal with SNS is the 'application' protocol which uses the vendor API keys ( GCM, APNS, ADM, etc. ) to send notification to/from the specific platforms, but that doesn't help me much when using cordova. I have to install a custom plugin to intercept those notifications. Not bad, but I figure there's a cleaner solution.

Given what I found it seems that AWS SQS is the best solution.

  1. Can AWS SQS deliver messages to multiple recipients (topic-like)?
  2. Do messages persist and get delivered when client comes back online?
  3. Is it feasible to create one queue for each item, and publish a message each time a bid is placed? This will result in a LOT of queues being created.



Aucun commentaire:

Enregistrer un commentaire