[BREAKGLASS] Asynchronous Google Cloud Messaging (GCM) Library
Go to file
2018-10-16 11:05:19 -07:00
src Update to latest jackson 2018-10-16 11:05:00 -07:00
.gitignore Asynchronous (with backoff retry) HTTP GCM implementation. 2015-01-01 15:14:05 -08:00
pom.xml Bump version to 0.1.5 2018-10-16 11:05:19 -07:00
README.md Add README 2015-01-02 19:49:54 -08:00

gcm-sender-async

An asynchronous HTTP library for Google Cloud Messaging.

Google provides a library for GCM (gcm-server), but it has a synchronous interface, along with an implementation that leaves something to be desired.

This is asynchronous, backed by Apache HttpAsyncClient, automatically handles asynchronous retries with backoff, simple to use, and fast.

Installing

Add to your pom:

<dependency>
  <groupId>org.whispersystems</groupId>
  <artifactId>gcm-sender-async</artifactId>
  <version>(latest version here)</version>
</dependency>

Using

String apiKey = "<myGcmApiKey>";
Sender sender = new Sender(apiKey);

ListenableFuture<Result> future = sender.send(Message.newBuilder()
                                                     .withDestination("<registration_id>")
                                                     .withDataPart("message", "hello world!");

Futures.addCallback(future, new FutureCallback<Result>() {
  @Override
  public void onSuccess(Result result) {
    if (result.isSuccess()) {
      // Maybe do something with result.getMessageId()
    } else {
      // Maybe do something with result.getError(), or check result.isUnregistered, etc..
    }
  }

  @Override
  public void onFailure(Throwable throwable) {
    // Handle network failure or server 500
  }
}

License

Copyright 2015 Open Whisper Systems

Licensed under the AGPLv3: https://www.gnu.org/licenses/agpl-3.0.html