All Projects → dtaniwaki → akka-pusher

dtaniwaki / akka-pusher

Licence: MIT license
Pusher meets Akka

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to akka-pusher

akka-cluster-on-kubernetes
Sample project for deploying Akka Cluster to Kubernetes. Presented at Scala Up North on July 21, 2017.
Stars: ✭ 35 (+94.44%)
Mutual labels:  akka
pusher-for-codeigniter
CodeIgniter library for Pusher PHP SDK
Stars: ✭ 27 (+50%)
Mutual labels:  pusher
akka-cookbook
提供清晰、实用的Akka应用指导
Stars: ✭ 30 (+66.67%)
Mutual labels:  akka
devto-scheduler
Live appointment scheduling, created for dev.to contest. Video: https://youtu.be/LT6YtcJ6dZI
Stars: ✭ 32 (+77.78%)
Mutual labels:  pusher
lila-ws
Lichess' websocket server
Stars: ✭ 99 (+450%)
Mutual labels:  akka
python-realtime-table
Building realtime table using Python and Channels
Stars: ✭ 12 (-33.33%)
Mutual labels:  pusher
food-delivery-ios-app
A food delivery application built using Swift for iOS. The application uses Pushers notifications feature to send push notifications to mobile devices.
Stars: ✭ 36 (+100%)
Mutual labels:  pusher
pusher
Pusher client library for Go
Stars: ✭ 15 (-16.67%)
Mutual labels:  pusher
project-manager-laravel
Project manager system - PHP and AngularJS
Stars: ✭ 17 (-5.56%)
Mutual labels:  pusher
akka-stream-kafka-template.g8
Template for Akka Streams & Kafka. Default impl: mirror a topic onto another one
Stars: ✭ 14 (-22.22%)
Mutual labels:  akka
akka-streams-interleaving
Akka Streams example of how to interleave Sources with priorities
Stars: ✭ 28 (+55.56%)
Mutual labels:  akka
ainterface
Runs an Erlang node on an ActorSystem of Akka.
Stars: ✭ 44 (+144.44%)
Mutual labels:  akka
akka-contextual-actor
A really small library (just a few classes) which lets you trace your actors messages transparently propagating a common context together with your messages and adding the specified values to the MDC of the underlying logging framework.
Stars: ✭ 17 (-5.56%)
Mutual labels:  akka
Quark
Quark is a streaming-first Api Gateway using Akka
Stars: ✭ 13 (-27.78%)
Mutual labels:  akka
chatkit-swift
Swift SDK for Pusher Chatkit
Stars: ✭ 40 (+122.22%)
Mutual labels:  pusher
kamon-akka
Kamon Instrumentation for Akka
Stars: ✭ 44 (+144.44%)
Mutual labels:  akka
protoactor-python
Proto Actor - Ultra fast distributed actors
Stars: ✭ 78 (+333.33%)
Mutual labels:  akka
alpakka-samples
Example projects building Reactive Integrations using Alpakka
Stars: ✭ 61 (+238.89%)
Mutual labels:  akka
slicebox
Microservice for safe sharing and easy access to medical images
Stars: ✭ 18 (+0%)
Mutual labels:  akka
akka-stream-mon
Throughput and latency monitoring for Akka Streams
Stars: ✭ 23 (+27.78%)
Mutual labels:  akka

akka-pusher

Maven Central Coverage CI License: MIT

Pusher Client under Akka's actor context.

The working sample with Play Framework is available here.

Prerequisites

  • Java 8 or higher
  • Scala 2.10 and Scala 2.11

Installation

Add the following to your sbt build (Scala 2.11.x):

libraryDependencies += "com.github.dtaniwaki" %% "akka-pusher" % "x.y.z"

Here, x.y.z is the akka-pusher package version you want to use.

Usage

import com.github.dtaniwaki.akka_pusher.PusherClient

implicit val system = ActorSystem("pusher")
val pusher = new PusherClient()
pusher.trigger("test_channel", "my_event", "hello world")
pusher.shutdown()

If you want to run another actor for pusher,

import com.github.dtaniwaki.akka_pusher.PusherActor
import com.github.dtaniwaki.akka_pusher.PusherMessages._

val system = ActorSystem("pusher")
val pusherActor = system.actorOf(PusherActor.props(), "pusher-actor")
pusherActor ! TriggerMessage("test_channel", "my_event", "hello world")

API

trigger

val result: Future[Try[Result]] = pusher.trigger("test_channel", "my_event", Map("foo" -> "bar"))

batch trigger

val result: Future[Try[Result]] = pusher.trigger(Seq(("test_channel", "my_event", Map("foo" -> "bar"))))

channels

val channels: Future[Try[ChannelMap]] = pusher.channels("presence-my_", Seq(PusherChannelsAttributes.userCount))

channel

val channel: Future[Try[Channel]] = pusher.channel("presence-my_channel", Seq(PusherChannelAttributes.userCount))

users

val users: Future[Try[UserList]] = pusher.users("presence-my_channel")

authenticate

case class Foo(body: String)
implicit val FooJsonSupport = jsonFormat1(Foo)
val channelData: ChannelData[Foo] = ChannelData("user_id", Foo("body"))
val params: AuthenticatedParams = authenticate("my_channel", "socket_id", Some(channelData))

validateSignature

val valid: Signature = validateSignature("pusher_key", "pusher_signature", "body")

Akka Actor Messages

TriggerMessage

(pusherActor ask TriggerMessage("channel-name", "event-name", "JSON OBJECT".toJson, Some("123.345"))).map {
  case Success(res: PusherModels.Result) => println(res)
  case Failure(e) => throw e
}

If the batchTrigger setting of PusherActor is true,

pusherActor ! TriggerMessage(channel, event, body.toJson, socketId)

The trigger will be executed in batch in 1000 milliseconds (default).

ChannelMessage

(pusherActor ask ChannelMessage("presence-my_channel", Seq(PusherChannelAttributes.userCount))).map {
  case Success(res: PusherModels.Channel) => println(res)
  case Failure(e) => throw e
}

ChannelsMessage

(pusherActor ask ChannelsMessage("presence-my_", Seq(PusherChannelsAttributes.userCount))).map {
  case Success(res: ChannelMap) =>
    println(res)
  case Failure(e) => throw e
}

UserMessage

(pusherActor ask UsersMessage("presence-my_channel")).map {
  case Success(res: UserList) =>
    println(res)
  case Failure(e) => throw e
}

AuthenticateMessage

val pusherRequest = AuthRequest()
(pusherActor ask AuthenticateMessage(
  "channel-name",
  Some("123.345"),
  Some(PusherModels.ChannelData(userId = "dtaniwaki", userInfo = Some(Map("user_name" -> "dtaniwaki", "name" -> "Daisuke Taniwaki").toJson)))
)).map {
  case res: PusherModels.AuthenticatedParams =>
    println(res)
}

ValidateSignatureMessage

(pusherActor ask ValidateSignatureMessage(key, signature, request.body.toString)).map {
  case Success(res) =>
    println(res)
  case Failure(e) =>
    throw e
}

Configuration

PusherClient use pusher scope in application.conf parsed by typesafe config.

pusher {
  appId=${?PUSHER_APP_ID}
  key=${?PUHSER_API_KEY}
  secret=${?PUSHER_API_SECRET}
  batchTrigger=true
  batchInterval=1000
}

Here, you can replace the variables or set them as environment variables.

Or, you can directly set the config by the costructor argument.

val pusher = new PusherClient(ConfigFactory.parseString("""pusher: {appId: "app0", key: "key0", secret: "secret0"}"""))

PusherClient Configuration

key type description
appId String Your pusher app ID.
key String Your pusher app key.
secret String Your pusher app secret.
ssl Boolean (default: false) Encrypt API request with SSL

PusherActor Configuration

key type description
batchTrigger Boolean (default: false) Flag to enable batch trigger requests. The batch size is 100 as pusher limits it.
batchInterval Int (default: 1000) Milliseconds to make batch trigger requests.

Test

sbt test

Coverage

sbt clean coverage test

codecov.io

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright

Copyright (c) 2015 Daisuke Taniwaki. See LICENSE for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].