Code Monkey home page Code Monkey logo

akka-stream-apns's Introduction

Reactive APNs Connector

Akka-stream-apns is an Apple Push Notification Service (APNs) connector built on top of Akka Streams. As of version 0.2, akka-stream-apns uses the latest HTTP/2-based APNs provider API.

Installation

resolvers += Resolver.bintrayRepo("reactivehub", "maven")

libraryDependencies += "com.reactivehub" %% "akka-stream-apns" % "0.10"

Quick Start

To use the connector, you need a push notification client SSL certificate and a device token. See System Requirements for more details on how to choose a TLS provider.

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.Source
import io.netty.channel.nio.NioEventLoopGroup
import reactivehub.akka.stream.apns.TlsUtil.loadPkcs12FromResource
import reactivehub.akka.stream.apns._
import reactivehub.akka.stream.apns.marshallers.SprayJsonSupport

object Main extends App with SprayJsonSupport {
  implicit val system = ActorSystem("system")
  implicit val _ = ActorMaterializer()

  import system.dispatcher

  val group = new NioEventLoopGroup()
  val apns = ApnsExt(system).connection[Int](
    Environment.Development,
    loadPkcs12FromResource("/cert.p12", "password"),
    group)

  val deviceToken = DeviceToken("64-chars hex string")

  val payload = Payload.Builder()
    .withAlert("Hello!")
    .withBadge(1)

  Source.single(1  Notification(deviceToken, payload))
    .via(apns)
    .runForeach(println)
    .onComplete { _ 
      group.shutdownGracefully()
      system.terminate()
    }
}

Payload Builder

Akka-stream-apns comes with a convenient payload builder. The payload is a JSON object with the required key apns and zero or more custom keys. The builder can use a JSON library of your choice; just mix in SprayJsonSupport, PlayJsonSupport or LiftJsonSupport or bring into scope your own PayloadMarshaller.

val payload = Payload.Builder()
  .withAlert("Bob wants to play poker")
  .withLocalizedAlert("GAME_PLAY_REQUEST_FORMAT", "Jenna", "Frank")
  .withTitle("Game Request")
  .withLocalizedTitle("GAME_PLAY_REQUEST_TITLE")
  .withLocalizedAction("PLAY")
  .withLaunchImage("Default.png")
  .withBadge(9)
  .withSound("chime.aiff")
  .withContentAvailable
  .withCategory("ACCEPT_IDENTIFIER")
  .withCustomField("acme1", "bar")
  .withCustomField("acme2", 42)

System Requirements

Akka-stream-apns works with Java 8 and newer.

HTTP/2 over TLS requires the use of ALPN. Java, however, currently does not support ALPN. As akka-stream-apns internally uses Netty's codec-http2 to connect to APNs servers, there are two options how to do TLS:

Limitations

  • No reconnect/resend on error (yet)

Consulting

Our professional consulting services are highly flexible to address specific issues such as troubleshooting or other services tailored to suit your needs.

Please contact us for more information.

akka-stream-apns's People

Contributors

lukaskostial avatar marcelmojzis avatar nremond avatar troypayne 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

Watchers

 avatar  avatar  avatar  avatar

akka-stream-apns's Issues

Netty ButeBuf recycle

Here when we use the ByteBuf's array to form a ByteString how and when release of ByteBuf input happens?

Since it is not released here the next handler will receive a ByteString and could not release it and that would be a memory leak. Right?

And even if it is released here then the backing array is in danger as it will be recycled.

out.add(ByteString.fromArray(msg.array(), msg.arrayOffset(), length))

Support for apns-collapse-id

I see support for headers like apns-id, but not for apns-collapse-id.

Can this be added? Or is there a way to add custom headers that I'm unaware of?

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.