Giter Site home page Giter Site logo

yuki24 / andpush Goto Github PK

View Code? Open in Web Editor NEW
81.0 6.0 10.0 145 KB

Android Push Notification in Ruby: The fastest client for FCM (Firebase Cloud Messaging)

Home Page: https://github.com/yuki24/andpush

License: MIT License

Ruby 99.16% Shell 0.84%
ruby android fcm firebase-cloud-messaging gcm google-cloud-messaging push-notifications push notifications

andpush's Introduction

Andpush Build Status

Andpush is an HTTP client for FCM (Firebase Cloud Messaging). It implements the Firebase Cloud Messaging HTTP Protocol.

The andpush gem performs about 3.7x faster than the fcm gem in a single-threaded environment.

If you are thinking to send push notifications from Rails, consider using the pushing gem, a push notification framework that does not hurt.

Installation

Add this line to your application's Gemfile:

gem 'andpush'

Or install it yourself as:

$ gem install andpush

Usage

You'll need your application's server key, whose value is available in the Cloud Messaging tab of the Firebase console Settings pane.

require 'andpush'

server_key   = "..." # Your server key
device_token = "..." # The device token of the device you'd like to push a message to

client  = Andpush.new(server_key, pool_size: 25)
payload = {
  to: device_token,
  notification: {
    title: "Update",
    body: "Your weekly summary is ready"
  },
  data: { extra: "data" }
}

response = client.push(payload)

headers = response.headers
headers['Retry-After'] # => returns 'Retry-After'

json = response.json
json[:canonical_ids] # => 0
json[:failure]       # => 0
json[:multicast_id]  # => 8478364278516813477

result = json[:results].first
result[:message_id]      # => "0:1489498959348701%3b8aef473b8aef47"
result[:error]           # => nil, "InvalidRegistration" or something else
result[:registration_id] # => nil

Topic Messaging:

topic   = "/topics/foo-bar"
payload = {
  to: topic,
  data: {
    message: "This is a Firebase Cloud Messaging Topic Message!",
  }
}

response = client.push(payload) # => sends a message to the topic

Using HTTP/2 (Experimental)

The current GitHub master branch ships with experimental support for HTTP/2. It takes advantage of the fantastic library, libcurl. In order to use it, replace Andpush.new(...) with Andpush.http2(...):

+# Do not forget to add the curb gem to your Gemfile
+require 'curb'

-client = Andpush.new(server_key, pool_size: 25)
+client = Andpush.http2(server_key) # no need to specify the `pool_size' as HTTP/2 maintains a single connection

Prerequisites

Make sure that your production environment has the compatible versions installed. If you are not sure what version of libcurl you are using, try running curl --version and make sure it has HTTP2 listed in the Features:

Curl version

If you wish to use the HTTP/2 client in heroku, make sure you are using the Heroku-18 stack. Older stacks, such as Heroku-16 and Cedar-14 do not ship with a version of libcurl that has support for HTTP/2.

If you are using an older version of libcurl that doesn't support HTTP/2, don't worry. It will just fall back to HTTP 1.1 (of course without header compression and multiplexing.)

Performance

The andpush gem uses HTTP persistent connections to improve performance. This is done by the net-http-persistent gem. A simple benchmark shows that the andpush gem performs at least 3x faster than the fcm gem:

$ ruby bench.rb
Warming up --------------------------------------
             andpush     2.000  i/100ms
                 fcm     1.000  i/100ms
Calculating -------------------------------------
             andpush     28.009  (± 7.1%) i/s -    140.000  in   5.019399s
                 fcm      7.452  (±13.4%) i/s -     37.000  in   5.023139s

Comparison:
             andpush:       28.0 i/s
                 fcm:        7.5 i/s - 3.76x  slower

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/yuki24/andpush. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

andpush's People

Contributors

narukami894 avatar yuki24 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

andpush's Issues

IOS Apn compatibility

Hi, this is actually a question.

Can one use your gem to send also IOS push notifications through Firebase assuming the APN is correctly connected through the firebase panel?

Thanks

NoMethodError (undefined method `new' for Andpush:Module):

NoMethodError (undefined method `new' for Andpush:Module):

newメソッドを使おうとすると存在しないと言われます。
なぜでしょうか?

[translation added by repo maintainer]
The Andpush#new initializer does not seem to exist. Any idea why this is happening?

Performance for 10M messages via FCM?

Hi, I'm needing to send 10M desktop web pushes in < 1 hour.

So far I see a few articles about how to do this with Elixir, here's the best article I think:

https://blog.discordapp.com/how-discord-handles-push-request-bursts-of-over-a-million-per-minute-with-elixirs-genstage-8f899f0221b4

Takeaways from article:

  • They use Elixir (I'd rather use ruby if possible, even if it's a bit slower)
  • They use Google XMPP API for FCM which they say is faster
  • There is a limit of 100 requests in flight at a time
  • There is connection draining (talked about here if you search DRAINING)

Unfortunately, I can't use broadcast messages because each message is personalized.

Do you have any idea what performance would be like while using Andpush and HTTP/2 or whatever goods you got?

Cheers!

How to set up a deep link?

Nice to meet you, I'm using andpush.

If I want to specify a deep link with andpush, how should I describe it?

I use it like this.

def self.push_notification(user, title, body)
    client  = Andpush.new(Setting.fcm_server_key)
    payload = {
      to: user.device.token,
      notification: {
        title: title,
        body: body
      },
      data: {
        extra: "data"
      }
    }

    client.push(payload)
  end

はじめまして、andpushを利用しています。

andpushでディープリンクを指定したい場合は、どのように記載すると良いですか?

このような感じで利用しています。

※英文はGoogle翻訳を使ったので文法に間違いがあると思います、ご容赦ください

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.